When ever I run the code below in Cocos 2D HTML or with bindings it seems to not add any of my functions but will add my Variables.

So:

cc.Class.extend({
   init: function(isDancing){
   this.dancing = isDancing;
},
   age : 5,
   dance: function(){
       return this.dancing;
   }
});

becomes :

 function anonymous() {
   this._super=null;this.age=this.age;
 }

Which I will get a undefined error when I try to call, dance().

有帮助吗?

解决方案

constructor function is 'ctor'(not 'init')

var Klass = cc.Class.extend({
   ctor: function(isDancing){
   this.dancing = isDancing;
},
   age : 5,
   dance: function(){
       return this.dancing;
   }
});

undefined

var el = new Klass(22);

undefined

el.dance()

22

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top