JS system function, JS function call mode

Source: Internet
Author: User

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

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.