Home > Web Front-end > JS Tutorial > Related methods of specifying function names in JavaScript_Basic knowledge

Related methods of specifying function names in JavaScript_Basic knowledge

WBOY
Release: 2016-05-16 15:56:45
Original
1236 people have browsed it

JavaScript 1.2 introduces the concept of function literals as a new way to define more than one function.

A function literal is an expression that defines an unnamed function.
Grammar

The syntax of a literal function is very similar to a function declaration, except that it is used as an expression, not as a declaration, and the function name is required.

<script type="text/javascript">
<!--
var variablename = function(Argument List){
            Function Body 
          };
//-->
</script>

Copy after login

Syntactically, you can create a literal function by specifying the function name:

<script type="text/javascript">
<!--
var variablename = function FunctionName(Argument List){ 
           Function Body 
          };
//-->
</script>

Copy after login

However, the name means nothing, so it's not worth using it.
Example:

Here is an example of creating such a function:

<script type="text/javascript">
<!--
var func = function(x,y){ return x*y };
//-->
</script>

Copy after login

You can call the following function in the above function:

<script type="text/javascript">
<!--
func(10,20); // This will produce 200
//-->
</script>

Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template