The code copy is as follows:
//Use object impersonation to realize js inheritance
function A(color) {
this.Acolor = color;
this.AshowColor = function() {
document.writeln("Acolor: " + this.Acolor);
}
}
function B(color, name) {
// Assign newMethod to A and call A's constructor
this.newMethod = A;
this.newMethod(color);
//Then delete the reference to A, so that he cannot be called in the future
delete this.newMethod;
this.Bname = name;
this.BshowName = function() {
document.writeln("Bname: " + this.Bname);
}
}
var objA = new A("red");
objA.AshowColor();
document.writeln("------------------------------------------------------------------------------------------------------------------------
var objB = new B("black", "demo");
objB.AshowColor();
objB.BshowName();
document.writeln("------------------------------------------------------------------------------------------------------------------------