in JS The functions are divided into : User-defined functions, system functions (lookup documents)
Introduction to commonly used functions eval
<HTML><Head></Head><Body><Scriptlanguage= "JavaScript">varStr="window.alert (' OK ')";//The requirement is to execute STR as a script.eval (str);//computes the JavaScript string and executes it as script code. </Script></Body><HTML>
Debug results:
Escape () and the use of the Unescape () function:
<HTML><Head></Head><Body><Scriptlanguage= "JavaScript">varstr1="China Hkust";//The escape () function encodes the string so that it can be read on all computers. //Escape and unescape () are often used together to prevent garbledvarstr2=Escape (STR1); Window.alert (str2);varSTR3=unescape (STR2); Window.alert (STR3);</Script></Body><HTML>
Escape () Code:
Unescape () function decoding:
How functions are called
Normal invocation:
① function name (passed to the function parameter 1, passed to the function parameter 2)
② through variables that point to functions: variable = function name
At this point the variable is equivalent to the function reference (pointer), you can call the function: function (actual parameter)
Special Note:
1. For a function call that has a return value, you can also use the returned result directly in the program.
For example:alert ("res=" +sum (2,3))
2. If there is no function to return a value, but you receive, return undefined.
3. Discussion on the question of the return value of the receive function
var myvar = Test (' abc ');
If the test function does not return a value, but you receive the return is undefine, if there is a return value, what is what is window.alert (myvar);
Case (js25-3.html):
<HTML><Head></Head><Body><Scriptlanguage= "JavaScript"src= "Js25-3.js"></Script><Scriptlanguage= "JavaScript">Test ('Hello world!'); Window.alert (test); //test equals functionvarMyVar=Test;myvar ('Beijing, China! '); Window.alert (myvar);</Script></Body><HTML>
JS file:
function Test (val) { Window.alert ("you entered is" +val);}
Test:
JS system function, JS function call mode