JS Closed Package

Source: Internet
Author: User

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

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.