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
WBOYOriginal
2016-05-16 15:56:451265browse

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>

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>

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>

You can call the following function in the above function:

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

Statement:
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