How JavaScript works behind the prototype

Source: Internet
Author: User

Let's start with a function.functionfn1 (name, age) { This. Name =name;  This. Age =Age ;  This. Say =function() {alert (' My name: ' + This. Name + ' and age: ' + This. Age); }}fn1.prototype.test=function() {alert (' Test ');}varF1 =NewFN1 (' JM ', 20); F1.say (); //pop-up my name JM and agef1.test ();//pop-up testWhat's going on here?

Something of its own. We need to know that each function has a reserved property prototype it returns an object

This object can be written or read.

Each function new object has an implicit property (__proto_ = Fn1.prototype) that points to the prototype of the constructor!

The following diagram illustrates the principle of prototype, (there are some references on the Internet):

How JavaScript works behind the prototype

Related Article

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.