cc.Class.extend not respecting functions

926 views Asked by At

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().

1

There are 1 answers

0
spirinvladimir On BEST ANSWER

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