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
Filed under: internet, JavaScript, object oriented, programming, software, technology |
Leave a comment