JavaScript Ptototype Note

>In fact, whenever a JavaScript programmer defines a function:

>function A() { /* Define constructor behavior here */ }

>Two objects are created: a constructor object (named "A"), and an anonymous prototype object associated with that constructor ("A.prototype").When creating an instance of that function:

>var a = new A();

>JavaScript creates a permanent link between the instance object ("a") and the constructor's prototype ("A.prototype"). This is the "private prototype" illustrated in the previous figure.

 

In JavaScript, every function has a property named "prototype" that refers to a prototype object. This prototype object in turn has a property named "constructor," which refers back to the function itself. It’s sort of a circular reference; 

 

posted on 2013-04-17 14:51  hhenliang  阅读(163)  评论(0编辑  收藏  举报

导航