Factory Paradigm : Properties « Object Oriented « JavaScript Tutorial






Factory functions create and return an object of a specific type.

function createObject() {
    var bufObject = new Object;
    bufObject.color = "red";
    bufObject.doors = 4;
    bufObject.showColor = function () {
        alert(this.color)
    };

    return bufObject;
}

var myHourse1 = createObject();
var myHourse2 = createObject();








25.5.Properties
25.5.1.Properties of an object can be defined dynamically after its creation
25.5.2.Factory Paradigm
25.5.3.Passing in of default values for the various properties in Object creation function