JavaScript prototype (some explanations on prototype usage)

Source: Internet
Author: User

You have a certain understanding of JavaScript. you are no stranger to jquery. You must have seen prototype when you look at jQuery source code, if you have any questions about prototype or want to learn more about it, you are welcome to continue reading it.

The original usage was to avoid repeated copies of random data in the constructor from being instantiated and later used in "inheritance". Note that JS semantics is not inherited, this is a human implementation. For the following titles in JavaScript, such as "object", "function", "type", and "method", I think it is important to understand them.

Each type in Javascript has the prototype attribute. In Javascript, the prototype attribute is interpreted as returning a reference to the prototype.

The function we write is also a type, and the object also has an attribute. prototype is the function attribute, which is also an object. The difference is that when a function is defined as a class, the process of creating a class instance (the new process) should refer to its prototype object and copy all properties of the prototype object to the new object. Therefore, we can see that prototype is a template, this template already exists before a new object. If you do not understand this section, let's continue to look at the example.


Please go to my personal website for further readingAddress: http://www.zingson.com/zing/157.html


You are welcome to share your resources on our website!


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.