JS prototype chain (ii) The principle of the--new operator

Source: Internet
Author: User

The principle of the new operator:

First step: Create an empty object that inherits the constructor's prototype object

Step Two: Execute the constructor and point this to the empty object

Step three: Return this result if the result returned after the constructor executes is an object type, otherwise the empty object created in the first step is returned.

The principle of the new operator is      var new2 = function (func) {          var o = object.create (func.prototype);  To generate a new object, the object inherits the constructor's prototype object          var k = Func.call (o);//executes this constructor and points this to O          if (typeof k = = = ' object ') {              return k;          } else {              return o;          }      };

  

JS prototype chain (ii) The principle of the--new operator

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.