The example usage of Function object Syntax in JavaScript
This article focuses on "the example usage of Function object syntax in JavaScript". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the example usage of Function object syntax in JavaScript".
Function object in JavaScript
The Function object in JavaScript is a function that creates a new one.
The method of use is as follows:
Grammar 1
FunctionfunctionName ([argname1 [,... [, argnameN]) {body}
Grammar 2
Reference:
FunctionName=newFunction ([argname1, [... argnameN,]] body)
Where functionName is a required option. * create the name of the function
Argname1...argnameN is optional. The list of parameters received by the function.
Body is optional. A string containing the block of JScript code that was executed when the function was called.
The basic data type in the function JScript. Syntax 1 creates function values that are converted by JScript to Function objects if necessary. JScript converts a function created with Syntax 2 to a Fnction object when calling a function.
Syntax 1 is the basic method for creating functions in JScript. Syntax 2 is another method for explicitly creating function objects.
For example, to create a function that adds the two parameters passed to it, you can do it in either of two ways:
Example 1
Functionadd (x _ ray) {return (x _ ray); / / performs the addition and returns the result. }
Example 2
Varadd=newFunction ("x", "y", "return (x)")
In both cases, you can call the function with the following line of code:
Add (2pr 3)
When calling a function, be sure to include parentheses and required arguments. Calling a function without parentheses causes the text of the function to be returned instead of the result of the function execution.
At this point, I believe you have a deeper understanding of "the example usage of Function object syntax in JavaScript". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!