(1) Declare an expression variable and define the expression for that variable. Such as:
Copy Code code as follows:
var func = function ()
{
/*body code*/
}
(2) defines a function expression and specifies the identity of the expression. Such as:
Copy Code code as follows:
function func ()
{
Body Code
}
(3) Use JavaScript built-in function object constructs. Such as:
Copy Code code as follows:
var func = new Function ("/*parameters*/", "/*body code*/");
Declaring a variable definition differs from using a function expression identity definition. We know that the function uses the reference delivery type when it occurs, using the variable definition to save the address reference of the expression, and using the flag definition to save the address of the expression. So when we change or redefine a variable, it doesn't cause the original expression to change, and when we change the identity, the corresponding expression changes. Such as:
Copy Code code as follows:
Declare a variable and define an expression reference to the variable
var test = function ()
{
Alert ("Reference test");
}
Defines an expression that holds its address information in Test1
function Test1 ()
{
Alert ("Reference test1");
}
Pass the expression referenced by test to reference
var reference = test;
Passes the address of the test1 expression to the Reference1
var reference1 = test1;
Change the reference to the variable test
Test = function ()
{
Alert ("New test");
}
Redefining data in an test1 address
function Test1 ()
{
Alert ("New Test1");
}
alert (reference);//The expression to which it is referenced does not change
Alert (REFERENCE1)//Because Reference1 is a reference to test1 address, reference1 content changes as the contents of Test1 address change