JavaScript this lifetime

Source: Internet
Author: User

Things have to be said from an unintentional print in a chrome console.

As we all know, JS a total of six data types, string, number, Undefined, Boolean, object, null. Of course, JavaScript also prepares reference types, which are constructed from object objects, such as the function, Array, Date ...

Here, Array instanceof Object .... These natural good understanding, then the array instanceof function what the hell is this? Then let's explore.

The diagram below, let's split the heart.

First of all, you have to understand a point of knowledge that all people in the world understand

    • All reference types (arrays, objects, functions) have a __proto__ property.
    • All functions are a prototype property, and his value is an object.
    • The __proto__ of all reference types points to the prototype (explicit object) of their constructors

The birth of a thing comes from a thing called Object.protoype, and that's right. Here's what the function, object, and array methods are.

Go ahead, print, look, object.prototype.__proto___.

Yes, that's the source of the story ... this is the first thing the creator has created ... He is the Lord of a nation.

Then, the creator gave birth to something called function, in order to highlight the hierarchical relationship, he let Function.prototype's __proto__ It points to the Object.prototyp (a prototype object that can also be understood as the constructor of a function). Don't believe me? You give it a try

With the chief minister, Object.prototype the most of his duties to him, all the messy things to you, yes, officials are like this. So the chief Minister began his hard work.

First construct a direct descendant of your own, and the function function is born, and he is the constructor of all the functions that you declare, and his __proto__ points to the prototype object of its constructor Function.prototype, see the following example.

(Note: The constructor in Foo.prototype is the constructor, and he is exactly equal to the Foo function.) He is not referring to the constructor of the current Foo function, but rather the constructor of the object that he constructs. The object/array itself does not have a structure
The ability to build the next generation, so it has no prototype prototype object, and his __proto__ attribute points to the prototype of its constructor, which is Foo.prototype. For a prototype prototype object of any function, its
__proto__ all pointed to the ancestors Object.prototype

 

Function of the completion of the work, the creator of the old feeling is still the shortcomings of what things, or not satisfied, so a lifetime, function you listen to, and then give me a thing called object. Funcion the second son of a fart, function Object

What is his prototype object, nature is the Lord of a country, object.prototype. Then the __proto__ of the object he constructed was pointing to Object.prototype.

The creator still does not feel satisfied, and commands the function way, according to the plan of creating object, and then create an array for me ... But he did a lot of work ....

So function began the manufacturing process of array, in order to let him do more work, he imitated his appearance, to Array.prototype added some special tools, let array.prototype.__proto__ still point to the Lord of a country, Object.prototype

The birth of JS Kingdom is now complete .... Hard function comrade ....

"Summary" believe you clear these, for JS is a big promotion, like Zepto, Vue and other source of reading will be more handy. All of these are in accordance with their own understanding, the birth order of each citation type in the article is debatable, but is to be able to understand more deeply. Hope that some students find explanations of the wrong place can also be generous to enlighten.

JavaScript this lifetime

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.