Defining the object methods outside of the factory functions and then pointing to them : Member Function « Object Oriented « JavaScript Tutorial
- JavaScript Tutorial
- Object Oriented
- Member Function
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();