不懂就问,请问 this._root!.frameMove(this._deltaTime); 这行代码里的 ! 是什么意思呢?
不对,好像理解错了。刚去看了下教程,感叹号是这个值可以被赋值为空,但这里强调为非空使用
找了下教程,总算看明白了
因为
this._root 是联合类型 Root | null;
this._root.frameMove 这样调用编译不过去,因为它可能是 null。
this._root!.frameMove 这样就明确地告诉编译器,这个不为 null 了。
参考
https://www.tslang.cn/docs/handbook/advanced-types.html
function broken(name: string | null): string {
function postfix(epithet: string) {
return name.charAt(0) + '. the ' + epithet; // error, 'name' is possibly null
}
name = name || "Bob";
return postfix("great");
}
function fixed(name: string | null): string {
function postfix(epithet: string) {
return name!.charAt(0) + '. the ' + epithet; // ok
}
name = name || "Bob";
return postfix("great");
}
该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。