cc.Class({
extends: cc.Component,
onLoad:function(){
setTimeout(function(){
this.node.destroy();
},1000);
}
});
我在一个节点的组建里面这么写,让这个节点加载后延迟1秒销毁;为什么会报这个未定义的错误
Uncaught TypeError: Cannot read property ‘destroy’ of undefined
cc.Class({
extends: cc.Component,
onLoad:function(){
setTimeout(function(){
this.node.destroy();
},1000);
}
});
我在一个节点的组建里面这么写,让这个节点加载后延迟1秒销毁;为什么会报这个未定义的错误
Uncaught TypeError: Cannot read property ‘destroy’ of undefined
this
用箭头函数
正确书写
onLoad:function(){
setTimeout(function(){
this.node.destroy();
}.bind(this),1000);
}
谢谢,大神