Visit Mozilla.org

Core JavaScript 1.5 Guide:Creating New Objects:Defining Properties for an Object Type

From MDC


[edit] Defining Properties for an Object Type

You can add a property to a previously defined object type by using the prototype property. This defines a property that is shared by all objects of the specified type, rather than by just one instance of the object. The following code adds a color property to all objects of type car, and then assigns a value to the color property of the object car1.

Car.prototype.color=null;
car1.color="black";

See the prototype property of the Function object in the Core JavaScript Reference for more information.

« Previous Next »