Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>insert title here</title>
<script type= "Text/javascript" >
/*i Summary:
1. Function name can be used as a variable, you can assign values, you can transfer values
2. Function name as parameter, passed to another function
*/
Two definitions of functions in ==================JS and function variable assignment ================
Defining a function in JavaScript can be understood as defining a variable
JS variables in the weak type of OH.
----------1
function Add1 () {
Alert ("Add1");
//}
So the function, as a variable, can be used as a parameter, and ADD1 points to the first address that this block of code stores in memory.
var add1=new Function ("alert (' Add1 ');"); /--------2
The above 1, 2 of the writing is completely equivalent to the declaration of a function in JS two ways
In fact, it is add1 that points to the function code block, the first address stored in memory.
As for specific how to store, heap or stack, here do not do more research.
var addtt=add1;//function name when variable is used, you can assign a value, or you can pass a value
ADDTT points to the function body
ADDTT ();
Two definitions of functions in ==================JS and function variable assignment ================
================== pass function variables as arguments ===========================
Basic format:
function Add2 (fun) {
Passing the function name as a parameter
Fun ();
}
ADD2 (ADD1);
//--------------------------------------
Function masterpiece parameters are used, while accepting parameters of the case demo
function Add (a) {
return n+10;
}
A: Numbers, fun: functions
function Addtest (a,fun) {
var t=fun (a);
return t;
}
var tt=addtest (22,add); this is OK.
Alert (TT);
================== pass function variables as arguments ===========================
</script>
<body>
</body>