문제

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