March 27, 2001 - Using the Call Method | WebReference

March 27, 2001 - Using the Call Method

Yehuda Shiran March 27, 2001
Using the Call Property
Tips: March 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

When an object is a superclass of another object, it's a good practice to call the prototype constructor function from the subclass constructor function. Here is an example:

function Shape() {
  this.area = 100;
}
function Square() {
  Shape.call(this);
}
Square.prototype = new Shape();
Shape1 = new Square();

The object Square calls its prototype constructor, Shape, using the call property notation:

Shape.call(this);