tutorial on the use of function () functions in Javascipt

Source: Internet
Author: User

This article mainly introduces the Javascipt function () functions of the use of the tutorial, is javascipt introductory learning in the basic knowledge, the need for friends can refer to the

A function statement is not defined as a new function, and you can define the only way in which your functions are used to construct the use of the operator dynamically.

Note: This is the terminology of object-oriented programming. The first time may feel not very accustomed, here is no problem.

Grammar

The following is the use of the new operator to create a syntax that uses functional function () constructs.

?

1 2 3 4 5 <script type= "Text/javascript" > <!--var variablename = new Function (ARG1, Arg2 ..., "Function body"); --> </script>

function () functions construct any number of expected string parameters. The last argument is the function body-it can contain arbitrary JavaScript statements, separated from each other by semicolons.

Note that the function () construct does not use any arguments, and specifies a name for it to create functions. An unnamed function created using the function () constructor is called an anonymous function.

Example:

Here is an example of creating a function:

?

1 2 3 4 5 <script type= "Text/javascript" > <!--var func = new Function ("X", "Y", "return x*y;"); --> </script>

This line of code creates a new function that is more or less equivalent to the syntax of a defined function:

?

1 2 3 4 5 6 7 <script type= "Text/javascript" > <!--function f (x, y) {return x*y;}//--> </script>

This means that you can call the above function as follows:

?

1 2 3 4 5 <script type= "Text/javascript" > <!--func (10,20); This would produce//--> </script>
Related Article

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.