1. Use prototype to complete single inheritance.
//Define a class A
function A(){
}
//Dynamically call the attribute color for class A, and the method sayColor
A.prototype.color = "blue";
A.prototype.sayColor = function(){
alert(this.color);
};
//Created a class B
function B(){
}
//Let B inherit from A
B.prototype=new A(); //new the object of A and assign it to the prototype of B. B contains all the properties and methods defined in A.
//Can the inherited sayColor be overridden?
B.prototype.sayColor=function(){
alert("Rewrite");
}
var b=new B();
b.color='red';
b.sayColor();