The prototype object is intended for use, mainly functions that will be called using the new operator to create new instances of objects.
Functions in JavaScript are first-class objects, which means that you can add elements to them and process them just like regular objects:
var STORE = { item : function() { } }; STORE.item.add = function() { alert('test 123'); }; STORE.item.add();
A typical use of a prototype object, as I said earlier, is when you instantiate an object by calling a constructor function with a new statement, for example:
function SomeObject() {}
All instances of SomeObject inherit members from SomeObject.prototype , because these elements will be accessed through a prototype chain.
Every function in JavaScript has a prototype object, because there is no way to know which functions are intended to be used as constructors.
CMS 20 Oct '09 at 4:15 2009-10-20 04:15
source share