Principles _javascript Techniques for JavaScript functional programming

Source: Internet
Author: User
Tags anonymous
calls to functions and methods in 1,javascript
In JavaScript, there are two ways to call a function. The general way is to put the arguments in parentheses, and the other way is to put both the function and the arguments in parentheses. Such as:
Copy Code code as follows:

function test (x)
{
alert (x);
}
Test ("Hello");
(test) ("Hello");
Equivalent to the following code
(function test (x)
{
alert (x);
}) ("Hello");
is also equivalent to the following code
(function (x)
{
alert (x);
}) ("Hello");

2, anonymous function
An anonymous function is a function or method that has no name. An anonymous function can be considered a one-time function. They are especially useful when you need to use only one function at a time. By using anonymous functions, the use of anonymous functions is more efficient because there are no related references and identities that are garbage collected after execution. Here's a simple comparison between anonymous functions and other reference or identity functions:
Copy Code code as follows:

function test (x)
{
Alert ("Define an identity function");
}
var test = function ()
{
Alert ("Point an anonymous function to a reference");
}
(Function ()
{
Alert ("I am an anonymous function");
} ();//This is actually an anonymous function that has been defined and executed

Most languages support the operation of a function as an operand (parameter). However, because the functions are positioned differently, they do not have the same result. When a function in JavaScript is used as a parameter, it is passed by reference. Function arguments are no different from normal arguments, and their results return unique values.
Copy Code code as follows:

function Test (func)
{
Alert (func);
}
Test (function () {return "anonymous function (execution result) as parameter"}) ());

Each variable of functional programming is generated on a temporary basis. Or it can be said that in the function of the concept of no variables, any data is based on the actual needs, according to a certain rule (function) after the calculation, which also to some extent to solve the problem of concurrent access to atomic variables.
Related Article

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.