You don't know. js-Mixed Object-Class

Source: Internet
Author: User

1, the class is a design pattern, many languages provide for the class-oriented software design of the native syntax, JS also has a similar syntax, but it is completely different from the classes in other languages.

2. Class means copy

3. JS does not automatically create a copy of the object as if it were a class.

4, in the case of inheritance or instantiation, JS object mechanism does not automatically perform replication behavior, in short, JS only objects, there is no class can be instantiated. An object is not copied to other objects, and they are associated.

5, Mixed mode (whether explicit or implicit) can be used to simulate the replication behavior of the class, but often produce ugly and fragile syntax, such as explicit pseudo polymorphism, which makes the code more difficult to understand and difficult to maintain.

Explicit mixing there is no way to emulate the replication behavior of a class, because objects can only copy references, cannot copy referenced objects, or the function itself. If you modify a shared function object, such as adding an attribute, both the parent and child classes are affected.

6, in general, in JS simulation class is not worth the candle, although can solve the current problem, but there will be more hidden trouble

You don't know. js-Mixed Object-Class

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.