as the title said. is it possible to subclass/inherits an existing binding classes purely in js?
I think the problem here is that instances of binding classes are not created by constructors, they use createXXX to create and binding to a native object. Thus makes an ordinary inherit fails.
——————-
eg.( if you can answer this question, you can also solve my problem )
function DerivedSprite(){} // a constructor for derived sprite
DerivedSprite.prototype.func = function(){
this.setAnchorPoint(cc.p(0, 0));
this.setPosition(cc.p(0, 0));
}
Question:
how to make DerivedSprite subclass from cc.Sprite and makes code below works.
var x = new DerivedSprite();
x.func();
parent.addChild(x);
try
var DerivedSprite = cc.Sprite.extends({
init:function(){
if (!this._super()) return false;
// Your init code
return true;
}
func:function(){
this.setAnchorPoint(cc.p(0, 0));
this.setPosition(cc.p(0, 0));
}
});
var x = new DerivedSprite();
x.init();
x.func();
parent.addChild(x);
you can learn cc.Class.extends to find out how the “_super()” works for all the inherits functions.
Thank you. That works.
Slipper S.G wrote:
try
[…]
>
you can learn cc.Class.extends to find out how the “_super()” works for all the inherits functions.