Javascript-js ask a new object to inherit the prototype array problem?

Source: Internet
Author: User

An element is added to the obj1 array, which is also added in the Obj2 array.
Do they inherit the array as a pointer? Everyone has an array of prototype this object?

//最后问一个很奇怪的问题(prototype中的array难道也只是一个指针?)

Thank you..

Reply content:

An element is added to the obj1 array, which is also added in the Obj2 array.
Do they inherit the array as a pointer? Everyone has an array of prototype this object?

//最后问一个很奇怪的问题(prototype中的array难道也只是一个指针?)

Thank you..

The first thing to understand is how to achieve inheritance.

1. The constructor has a prototype property.
2. Each instance of a constructor has a __proto__ prototype property that points to its constructor.
3. When accessing an attribute that does not exist on an object itself, it is searched by the __proto__ prototype of its constructor.
4, so the call obj1.array access is Person.prototype.array ; obj2.array Person.prototype.array
5, obj1 with obj2 the common use of this one array .
6, so whether to pass by value or reference delivery is irrelevant. Each instance was originally accessed by aprototype
Each instance does not save a copy of the constructor prototype.

  • 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.