The prototype property is an object created by JavaScript for every function() instance. It links object instances created with the new keyword back to the constructor function that created them.

By this way instances can share, or inherit, common methods and properties. The sharing occurs during property lookup.

Consider an example below. An array "myArray" is created from the Array() constructor, and then join() method is invoked.

var myArray = new Array('foo', 'bar');

console.log(myArray.join()); // logs 'foo, bar'

In the above example join() method is not defined as a property of the Array() constructor's prototype property. Since join() is not found within the array object instance, JavaScript looks up the prototype chain for a method called join().

Related Tutorial
Follow Us #