In-depth understanding of JavaScript prototypes and Closures (3)--prototype prototypes

Source: Internet
Author: User

The object mentioned above is a function created, and a function is an object. An object is a collection of properties, and there is no method.

Each function has an attribute--prototype.

The property value of this prototype is an object (a collection of attributes), which, by default, has a constructor attribute pointing to the function itself.

, Supertype is a function that has a prototype property whose property value is an object, which has a constructor property by default, and the property value of the property points to the function itself.

For example, Supertype is a function, and the right-hand box is its prototype.

The prototype acts as an object, a collection of properties, a constructor property by default, and some other properties. For example, there are several other properties in the prototype of object.

You can also add your own properties to the prototype of your own custom method.

1 function Fn () {}; 2 fn.prototype.name= ' Zhang San '; 3 fn.prototype.getyear=function  () {4     return 1988; 5 };

From the drawing structure, you can see that the Name property and the GetYear method that you manually added are added to the prototype prototype. And look at the following example

1 function Fn () {}; 2 fn.prototype.name= ' Zhang San '; 3 fn.prototype.getyear=function  () {4     return 1988; 5 }; 6 var fn=New  fn (); 7 Console.log (fn.name); 8 Console.log (Fn.getyear ());

FN is a function, and the FN object is from the FN function new, so that the FN object can invoke the properties and methods in Fn.prototype.

Each object has a hidden property--_proto_, which references the prototype that created the function, fn._proto_ = = = Fn.prototype

The _proto_ here is called an implicit prototype of the object.

In-depth understanding of JavaScript prototypes and Closures (3)--prototype prototypes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.