Constructor Paradigm : Constructor « Object Oriented « JavaScript Tutorial






A class name is the name of the constructor.

A constructor 'acts as' a factory function.

No object is created inside the constructor.

this keyword is used in constructor.

When a constructor is called with the new operator, an object is created before the first line of the constructor.

Constructors create a separate copy for each object.

function Car(sColor, iDoors) {
    this.color = sColor;
    this.doors = iDoors;
    this.showColor = function () {
        alert(this.color)
    };
}

var my1 = new Car("red", 4);
var my2 = new Car("blue",3);








25.3.Constructor
25.3.1.Constructor Paradigm
25.3.2.Object constructor
25.3.3.Constructor Example
25.3.4.Constructor prototype
25.3.5.Use Form input data to construct an object
25.3.6.Class factory example