Prior to the closure of the understanding of the first is to prevent variable pollution, two active objects are not destroyed, the active object is not destroyed, only return function array object, but always feel understanding or not so thorough
According to JavaScript advanced programming, read the seventh chapter better understand under
One: function declaration promotion
Test (); No error.
function Test () { alert (one); }
Test2 (); Error test2 is not a function (...)
var test2 = function () {
Alert (22);
}
function declarations are function declarations and function executions are promoted to the top of the function, and function expression variable expressions simply elevate the declaration
Two: Anonymous functions
No identifier is anonymous after function
var test=function() { alert (one); }
Three: Closures
Closures are variable functions that have access to another function scope
A list of JavaScript advanced programming Books
functioncreatecomparisonfunction (PropertyName) {return function(Object1, object2) {varValue1 =Object1[propertyname]; varvalue2 =Object2[propertyname]; if(Value1 <value2) { return-1; } Else if(Value1 >value2) { return1; } Else { return0; } };}
var compare = createcomparisonfunction ("name");
var result = Compare ({name: "Nicholas"}, {name: "Greg"});
Because the closure contains the scope of the function, do not destroy the active object, but also more memory than the general function, the excessive use of closures may lead to more memory consumption, (in fact, the heart of the OS feel that they do not usually use a lot of closures)
JS Closed Package