& Compulsory face questions often test the characteristics, advantages and disadvantages --js closures (plus a small example)

When the function is returned to the internal and external storage, will produce closures. Closures produced original scope chain is not released.

Closures can be understood as, write a function, then this phenomenon closure.

concept:

 

 

basis:

The main is: add reduce out is returned, it will tightly grasp the test () in the AO (data n)

 

Using the object form

 

 

depth:

 

 However, we expect the output is printed (0-9), then print out how we expect it?

Comprehensive analysis of the figure, the output 10 10 reason is that we become 10 to perform functions in i, then if we can immediately execute a function,

It is not to be output 0-9 out?

Act One:

 

Act II:

 Act III :( most common most common method)

 

 

 

 

 

To prove Act III common here that a face questions

12345, click digital, output index, respectively, and their corresponding index

 

 

Guess you like

Origin www.cnblogs.com/snowbxb/p/11579569.html