JS closure, anonymous function concept

Source: Internet
Author: User

var function (ARG) {  // function body };

Anonymous function: Creates a function and assigns it to a variable, in which case the function created is called an anonymous function because there is no identifier behind the function keyword. (anonymous functions are sometimes called lambda functions). The Name property of the anonymous function is an empty string.

Note: FireFox, Safari, Chrome, and opera all define a nonstandard Name property for the function, which gives you access to the name specified by the function. The value of this property always equals the identifier followed by the function keyword.

Closures are functions that have access to variables in another function scope. A common way to create closures is to create another function inside the function.

    functioncomparison (PropertyName) {return function(object1,object2) {varValue1 =Object1[propertyname]; varvalue2 =Object2[propertyname]; if(value1>value2) {                return-1; }Else if(value1>value2) {                return1; }Else{                return0;    }        }; }

JS closure, anonymous function concept

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.