//採用物件冒充的方式實作繼承js
function (color) {
this.Acolor = color;
this.AshowColor = function() {
document.writeln("Acolor: " this.Acolor);
}
}
function B(color, name) {
//將newMethod賦值A,呼叫A的建構子
this.newMethod = A;
this.newMethod(color);
/ /然後刪除對A的引用,這樣以後不能呼叫他
delete this.newMethod;
this.Bname = name;
this.BshowName = function() {
document.writeln ("Bname: " this.Bname);
}
}
var objA = new A("red");
objA.AshowColor();
document.writelnln ("----------------");
var objB = new B("black", "demo");
objB.AshowColor();
objB.BshowName();
document.writeln("----------------");