我正在创建一个新的类定义Button
,它扩展了EaselJS中现有的Container
类。没有问题。但是,我也希望Button
继承超级All
,以便Button
也可以访问其.banana
和.eatBanana
。我该怎么做?
(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');
}());
答案 0 :(得分:1)
Javascript和扩展名CreateJS不支持多重继承。你可以:
Button.prototype.doSomething = All.prototype.doSomething
或myButton.doSomething = All.prototype.doSomething
。DisplayObject.prototype.doSomething = All.prototype.doSomething
。