我不晓得是不是Cocos对原生的JS上下文环境做了什么,以下代码跟预期输出不一样:
Creator 版本: 3.7
目标平台: PC chrome
import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('Main')
export class Main extends Component {
start() {
new Data();
}
update(deltaTime: number) {
}
}
abstract class AbstractBase {
public aa: number;
constructor() {
this.aa = 2;
this.create();
}
abstract create()
}
class Data extends AbstractBase {
public bb: number;
create() {
this.bb = 222;
setInterval(() => console.log(this), 1000);
}
}
预期应该是bb是222,但是奇怪的事情发生了结果是undefined,遇到这种问题实在是让人抓狂