On the nature of JS

Source: Internet
Author: User

  js has three kinds of memory   One is function   second is the stack of functions   Three is the object or heap   each has a feature   there are many heaps   every function is working on a heap It can add an object that can be referenced on this heap (through this. Variable =xxx)   or use parent heap (via __proto__)   object has child objects as if a forest with countless objects and function objects (tree structure) each object created has __ Proto__, which points to its inherited objects, objects through the __proto__ chain can inherit the methods of other objects and instances of members, which can be easily migrated to other object branches in a browser environment where window represents the root of all heaps (function () {...}) () These writes can create an anonymous heap of this anonymous heap hanging in the nearest heap of sub-heaps to avoid contamination   functions can be added by prototype (such as function name. prototype. =function ()) and transformation Constructors ( Prototype.constructor)   So functions can also be built into a forest so functions can build a lot of things under prototype   The prototype of the object function of the prototype pointer function also has a constructor function   representation constructor   So the prototype of the constructor function to the function function is equivalent to the parent space of the function. The   function can inherit a sub-function by "prototype. =function () {}" in the name of a functor   can also be passed "function name. Prototype= an Object" To inherit all the member names and methods of an object   so the essence of __proto__ and prototype is the same, which means that the parent space is just a function of the object, one acting on the functions, but the function is only at the time of the operation of the value, so there is a very big difference  apply,call,bind can let a function use an object heap branch   stack is growing and cutting in the run   one function cannot use the stack of another function   via new or object.create   can Create a function to convert to an object or heap  new execute this function   operate on this heap   summarize: JS can build a forest of objects and functions, canTo easily migrate objects and function branches, compare similar lisp  recommended reading: Https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators /thishttps://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/object/prototype   

JS essence theory

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.