We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我在查看文档http://www.cocos.com/docs/creator/scripting/class.html的时候,遇到一个问题。 下面是文档中的代码demo。 var Shape = cc.Class({ ctor: function () { cc.log("Shape"); // 实例化时,父构造函数会自动调用, } });
var Square = cc.Class({ extends: Shape, ctor: function () { cc.log("Square"); // 再调用子构造函数 } });
var square = new Square(); //以上代码将依次输出 "Shape" 和 "Square"。
//如果把上面的代码拆分成2个文件后调用, //Shape.js cc.Class({ ctor: function () { cc.log("Shape"); // 实例化时,父构造函数会自动调用, } });
//Square.js var Shape = require('Shape'); cc.Class({ extends: Shape, ctor: function () { cc.log("Square"); // 再调用子构造函数 } });
//helloworld.js中调用 var Square = requir('Square'); var square = new Square(); //这个类会查询不到,然后报错。如果我现在让Shape类继承于cc.Component后,就可以了。 //Component 是特殊的 CCClass,不能定义构造函数,它的构造职能可由 onLoad 方法代替。我现在的初衷只是定义一个常见的类,不需要继承Component。
The text was updated successfully, but these errors were encountered:
ok. 用module.exports导出就ok了。
Sorry, something went wrong.
No branches or pull requests
我在查看文档http://www.cocos.com/docs/creator/scripting/class.html的时候,遇到一个问题。
下面是文档中的代码demo。
var Shape = cc.Class({
ctor: function () {
cc.log("Shape"); // 实例化时,父构造函数会自动调用,
}
});
var Square = cc.Class({
extends: Shape,
ctor: function () {
cc.log("Square"); // 再调用子构造函数
}
});
var square = new Square();
//以上代码将依次输出 "Shape" 和 "Square"。
//如果把上面的代码拆分成2个文件后调用,
//Shape.js
cc.Class({
ctor: function () {
cc.log("Shape"); // 实例化时,父构造函数会自动调用,
}
});
//Square.js
var Shape = require('Shape');
cc.Class({
extends: Shape,
ctor: function () {
cc.log("Square"); // 再调用子构造函数
}
});
//helloworld.js中调用
var Square = requir('Square');
var square = new Square();
//这个类会查询不到,然后报错。如果我现在让Shape类继承于cc.Component后,就可以了。
//Component 是特殊的 CCClass,不能定义构造函数,它的构造职能可由 onLoad 方法代替。我现在的初衷只是定义一个常见的类,不需要继承Component。
The text was updated successfully, but these errors were encountered: