创建childClass类,继承于cc.Component,然后获取实例化对象childJS,将childJS作为组件添加到节点,失败。求大神指点~
var childClass = cc.Class({
extends: cc.Component,
properties: {
},
onload: function (dt) {
cc.error('hello, child');
},
clickTest: function () {
cc.log('click Test');
}
});
var childJS = new childClass();
var childNode = new cc.Node('childNode');
childNode.addComponent(childJS);
this.node.addChild(childNode);
报错信息:
Simulator: addComponent: The component to add must be a constructor
应该在哪里添加构造函数吗,看了官方文档,但不太懂~