Deep understanding of JavaScript prototypes and Closures (5)--instanceof

Source: Internet
Author: User

For value types, you can use TypeOf to judge, but typeof the reference type when the return value is only object/function, do not know exactly which one. The instance will be used at this time. For example

, F1 is created by the Foo function, but why is "F1 instanceof Object" true?

As for why later, say the rule of instanceof judgment. According to the above code see:

The first variable of the instance operator is an object, temporarily called A; the second variable is generally a function, temporarily called B.

The rule of instance is to find the line along the _proto_ of a, and to find it along the line of the prototype of B, if both lines can find the same reference, that is, the same object, so long returns True, and returns False if no coincident is found.

According to the above rules, you can see that "F1 instanceof Object" All points to object.prototype, so it returns true.

By the above rules, more bizarre phenomena can be explained, such as:

As can be seen from the above picture, the end is pointing to a place.

Instance represents an inheritance relationship, or the structure of a prototype chain.

Deep understanding of JavaScript prototypes and Closures (5)--instanceof

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.