Object Constructor
function car (make, model, color)
{
this.make=make || “unknown”;
this.model=model || “model”;
this.color=color||”unpainted”;
}
To give universal property to all new car objects, object protoypes are used
car.prototype.display=function()
{
msg.innerHTML += “<p> Your car is a “ + this.color + “ “ + this.make +” “ + this.model + “.</p>”;
}
To create new car objects
var fordCar=new car(“Ford”, “Mustang”, “blue”);
Prototypes can be universally created for any new objects using the syntax
Object.prototype.display=function()
{
msg.innerHTML += “<p> Your car is a “ + this.color + “ “ + this.make +” “ + this.model + “.</p>”;
}
In this care any newly created object can inherit the display property.
For example:
var truck={};
truck.display();