Defining the object methods outside of the factory functions and then pointing to them : Member Function « Object Oriented « JavaScript Tutorial





function showColor() {
    alert(this.color);
}

function createObject(sColor, iDoors) {
    var bufObject = new Object;
    bufObject.color = sColor;
    bufObject.doors = iDoors;
    bufObject.showColor = showColor;
    return bufObject;
}

var myHourse1 = createObject("red", 4);
var myHourse2 = createObject("blue",3);
myHourse1.showColor();
myHourse2.showColor();










25.4.Member Function
25.4.1.Defining the object methods outside of the factory functions and then pointing to them
25.4.2.Create an Object with member method
25.4.3.Add member function
25.4.4.Adding method to a class using prototype
25.4.5.Custom objects and associative object arrays
25.4.6.Instance method
25.4.7.Call object member function