contents   index   previous   next



Prototype property

 

For the technically inclined, objects have a prototype property. Instance properties and methods are attached to the prototype property of an object. As an illustration, assume that two new methods and two new properties are added to the String object. The instance property and method are added to the prototype property of the String object, whereas, the static property and method are added to the String object itself.

 

The following two declaration lines illustrate an instance property and an instance method:

 

String.prototype.newInstanceProperty

String.prototype.newInstanceMethod()

 

The following two declaration lines illustrate a static property and a static method:

 

String.newStaticProperty

String.newStaticMethod()

 

 

The following code fragment illustrates the differences in using these properties and methods.

 

   // Begin an instance of a String object

var newStr = "an example string";

var instVal = newStr.newInstanceProperty;

newStr.newInstanceMethod();

   // Use the static property and method directly

var statVal = String.newStaticProperty;

String.newStaticMethod();