Hybrid Constructor/Prototype Paradigm : prototype : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » prototype »

 

Hybrid Constructor/Prototype Paradigm








Use the constructor paradigm to define all nonfunction properties of the object.

Use the prototype paradigm to define the function properties (methods) of the object.








function Car(sColor, iDoors) {
    this.color = sColor;
    this.doors = iDoors;
    this.drivers = new Array("A""B");
}

Car.prototype.showColor = function () {
    alert(this.color);
};

var myHourse1 = new Car("red"4);
var myHourse2 = new Car("blue"3);

myHourse1.drivers.push("C");

alert(myHourse1.drivers);    
alert(myHourse2.drivers);







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» prototype