PDA

View Full Version : How to understand prototype in javascript



fanzhengwei
3 Mar 2010, 12:40 AM
Hello, everyone! I am using ExtJs in my programming. Now, I am puzzled by "prototype".
Who can give me some document about prototype or tell me how to use prototype.
Thanks! Best wishes!

Animal
3 Mar 2010, 2:14 AM
You'd be better off buying a Javascript book.

But basically a prototype is an object, shared between all instances of a class which is the final place searched when resolving property references.

So if you reference



myPanel.setTitle('foo');


It will first look in the instance for a property names "setTitle". There is no property in Panels called "setTitle". So it then resolves it from Ext.Panel's prototype.

It's the repository of shared properties of a class.