Calling a super-type constructor inside a subtype constructor
Remember, a function is simply an object that executes code in a particular environment, so you can also execute a constructor on a newly created object by using call () and apply ()
function Supertype () {
this.colors=["Red", "Blue", "green"];
}
Function subtype () {
Inherited the supertype.
Supertype.call (this); //seconded a super-type constructor
}
var instance1=new subtype ();
Instance1.colors.push ("yellow");
Console.log (instance1.colors);
var instance2=new subtype (); ["Red", "Blue", "green", "yellow"]
Console.log (instance2.colors);//["Red", "Blue", "green"]
By using call () or apply (), the Supertype constructor is actually called in the context of the newly created subtype instance, so that it executes on the new subtype object
All object initialization code defined in the Supertype () function. As a result, all instances of subtype will have their own colors properties.
Implementing inheritance by borrowing constructors