• RSS Unknown Feed

    • An error has occurred; the feed is probably down. Try again later.
  • Meta

JavaScript Instance Properties

A constructor that is created in JavaScript can have properties defined for it. Each instantiation of the constructor has it’s own copy of the properties. These are called ‘instance properties.’

For example, suppose the following constructor was defined:

function Dog()
{
this.legs = 4;
}

From this constructor, two instances of the Dog class could be instantiated:

var myDog = new Dog();
var myDog2 = new Dog();

Each of these instances has the same value for the ‘legs’ property but they eahch have their own copy.

document.write(myDog.legs);
document.write(myDog2.legs);

Related articles:
Object-oriented JavaScript
JavaScript Instance Methods

Leave a comment