Implementation principle of New-prototype object-oriented in Javascript

Source: Internet
Author: User

Javascript's new is just a simulation of the class. This is why JavaScript classes are not classes in the industry-because they are simulated.

In fact, the New Keyword of JavaScript only does five things.

1. Create an object
2. Search for all the methods and attributes on the prototype of the class and copy them to the created object. (Note: if the prototype has the function, array, or object attributes, copy only the pointer)
3. Point this in the constructor classa to the created object.

4. The _ PROTO _ of the created object points to the prototype of the class.
5. Execute the constructor class

Original article: http://blog.csdn.net/spring21st/article/details/6307261

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.