After Rollo (http://heeroluo.net/) pointing ~ ~ and read the "effective JavaScript Item 11 Master Closure" This article, the closure has a clearer understanding of the. In order to avoid learning without thinking is not the case, write down my understanding of closures, the right to record.
1: The function can access variables outside of it.
function cupshow (color, weight) { Console.log (' This cup: ' + ' + color + ' + weight);} function Cupmake (sourcefn) { var color = ' Red '; var weight = ' 50g ';
The above code passes the Cupshow function as a parameter to Cupmake. The color variable and the weight variable are accessed inside Cupmake.
2: Closures can also be accessed after the function that created them returns.
function cupshow (color, weight) { Console.log (' this cup: ' + ' + color + ' + weight);} function Cupmake (sourcefn) { returnfunction() { sourcefn.apply (this , arguments); };} var closure = Cupmake (cupshow); Closure (//
After the Cupshow function is returned by Cupmake in the above code, Cupshow can still be accessed inside the anonymous function.
My understanding of closures