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.