We all say that JavaScript properties are many, can not remember, various structures are difficult to understand. Indeed JS is a quick way to improve the difficult language, but there are other ways to assist the memory. The following is to discuss the JS of a major difficulty-object layout, exactly how the person who designed JS this language was how to do? What did you become when you finished the design?
Let's look at a picture:
I believe you are not unfamiliar with this picture, the constructor has a prototype attribute pointing to its prototype. The opposite prototype also has a constructor pointing to the constructor. At the same time the instance also has a constructor point to the constructor, which is simply tied to each other for fear of not finding it, is it?
There is also a __proto__ attribute that we call the secret link, forgive me to see this attribute at first sight to feel special strange, _ Underline all use, hump naming rule? OK, this is a part of the browser exposed to a pointer, maybe when the design was casually written out, suddenly found that the goods a little use left (purely personal speculation).
The attached test code for the children's shoes can be played by themselves:
<! DOCTYPE html>
Above is only the basis, the following is the real focus, in order to modify this picture I was painstakingly, racked my brains, do not know how many brain cells died.
Maybe everyone has seen dizzy, nothing to take a cup of coffee slowly look. The following is the corresponding proof code, friendship tips Sublimetext look more cool:
<! DOCTYPE html>I believe that after reading these code and the original comparison of the relationship between the JS object has been well-known, and indeed at the beginning I also let this goods dizzy dizzy, but after drawing this picture has felt nothing. You can draw it yourself.
Original address: Please click here
Javascript--15 rule parsing JavaScript Object layout (__proto__, prototype, constructor)