I'm creating a new class definition Button
that extends an existing Container
class in EaselJS. There are no problems with that. However, I'd also like Button
to inherit from a super class All
, so that Button
also has access to its .banana
and .eatBanana
. How do I go about this?
(function() {
function All() {
this.banana = 0;
}
var p = All.prototype;
p.eatBanana = function() {
alert(this.banana);
}
window.All = All;
}());
(function() {
function Button(apple) {
this.apple = apple || 0;
this.Container_constructor();
}
var p = createjs.extend(Button, createjs.Container);
p.sayHi = function() {
alert(this.apple + this.banana);
}
window.Button = createjs.promote(Button, 'Container');
}());
Javascript, and by extension CreateJS, does not support multiple inheritance. You could:
Button.prototype.doSomething = All.prototype.doSomething
or myButton.doSomething = All.prototype.doSomething
.DisplayObject.prototype.doSomething = All.prototype.doSomething
.