JavaScript-related knowledge

Source: Internet
Author: User
Tags closure

New concept of scopes and closures
How to differentiate where data is stored in memory in a heap, stack, or pool
1. see Var or function must be in the stack, the result of TypeOf is function
2.typeof results if it's not an object, it's in the pool.
3.typeof results if the object is in the heap.
Closed Package
Temporary closures are generated by function calls
The closure also divides the stack and the heap two areas, the variables defined in the closure in the closure of the stack, we call the local
Variable
is not a variable defined in a closure, we call it a global variable
Scope
The scope of a local variable only works in the current closure
The scope of a global variable can be accessed in any closure, and the scope of the global variable is actually the Window object
JS Execution Process
1. Increase the variables (functions) in the current closure (the global object is also equivalent to a closure) (so you can precede the function
Call function)
2. "From the top down"
3. When the closure is encountered, there will be repeated steps 1 and 2

Constructor
1. In JavaScript, constructors are functions, so we call constructors the constructor function
2. constructor function The first letter is the upper case of the normal function The first letter is lowercase
3. The name of the constructor function is usually the name of the normal function of the noun. Verb
4. Use a constructor function to invoke a normal function through the New keyword
constructor function and normal function using
Normal function calls create a temporary closure space
because the code in the closure is finished, the space disappears. The
usually calls the normal function, focusing on what is being done and what results are returned. The call to the
constructor function (new) creates a non-temporary closure space
New creates a chunk of memory space in the heap, and the constructor is called, and the constructor returns the address of the memory space by default.
(constructor function does not return, or this is returned by default)
1.this represents the reference to the current memory space
2.this represents the caller's reference
Constructor (constructor) and objects (object The
Prototype (prototype)
prototype is itself an object
All constructors have prototype this prototype property
all objects created by this constructor (new) can share this prototype
* The main constructor is the ability to create objects, all defined in prototype, because prototype is a shared instance (singleton)
* prototype used to define shared functions, or define shared default value properties

Private members
By defining var local variables or functions in the this scope
Prototype
Each constructor function has a prototype (object), in which the so-called prototype is actually an object
Extending the prototype of the System Builder
Every object that comes out of this constructor function, they have a default property called prototype, and the address of the object is the address of the prototype inside the constructor.
Inherit the prototype chain
All objects are inherited with an object
The *call method is used to change the this reference of the closure that is created when the method call
The *apply method is used to change the this reference of the closure that is created when the method call
The difference is that the call parameter is a pass, the Apply parameter is an array of ways to pass
*arguments is an object that is built into the system to represent the user's incoming parameter list (array) when the function is called.

JavaScript-related knowledge

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.