Mega Code Archive

 
Categories / JavaScript Tutorial / Object Oriented
 

Hybrid ConstructorPrototype 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);