Constructor prototype : Constructor : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » Constructor »

 

Constructor prototype

















<html>
<head>
<title>Example</title>
</head>
<body>
<script type="text/javascript">
function Car(sColor, iDoors, iMpg) {
    this.color = sColor;
    this.doors = iDoors;
    this.mpg = iMpg;
    this.owners = new Array("A""B");
}

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

var oCar1 = new Car("red"423);
var oCar2 = new Car("blue"325);

oCar1.owners.push("C");

document.write(oCar1.owners);
document.write(oCar2.owners);

</script>

</body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» Constructor