Constructor stealing
Constructor Stealing is to call the Shape constructor from within the Rectangle constructor.
function Shape() {
this.colors = ['red', 'blue', 'green'];
}
function Rectangle() {
Shape.call(this);
}
The apply()
and call()
methods can be used to execute a constructor on the newly created object.