Constructor prototype : Constructor « Object Oriented « JavaScript Tutorial






<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", 4, 23);
var oCar2 = new Car("blue", 3, 25);

oCar1.owners.push("C");

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

</script>

</body>
</html>








25.3.Constructor
25.3.1.Constructor Paradigm
25.3.2.Object constructor
25.3.3.Constructor Example
25.3.4.Constructor prototype
25.3.5.Use Form input data to construct an object
25.3.6.Class factory example