Object Oriented JavaScript Tutorial

This method uses a flag (_initialized) to determine if the prototype has been assigned any methods yet.
The methods are only created and assigned once.

function Car(sColor, iDoors) {
    this.color = sColor;
    this.doors = iDoors;
    this.drivers = new Array("A", "B");
    if (typeof Car._initialized == "undefined") {
        Car.prototype.showColor = function () {
            alert(this.color);
        };
        Car._initialized = true;
    }
}