The way to create a javascript dynamic function is to use the function object to define it. The basic format of the dynamic function [var variable name = new function ("parameter 1", "parameter 2", "parameter n", "execution statement ")].
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
How to create a javascript dynamic function:
Dynamic functions must be defined using function objects (function is an object in javascript, which is fixed and unchangeable. It stipulates that function The "f" of the object must be capitalized. When it is a function, it is a keyword used when defining the function: function ppp (x, y). When it is a function (when f is capitalized), it is an object in JavaScript)
Basic format for creating dynamic functions:
var 变量名 = new function(”参数1“,”参数2“,”参数n“,”执行语句”);
Use the new keyword (new is a keyword in javascript and is also fixed. We must use new to create this function object when defining a dynamic function)
First define a variable ar variable name. Here, the variable name is random, then use the new keyword to create a function object, and then assign this object to this arbitrary variable, which is the var variable. Name = new function
The parentheses after function first contain the parameters passed to the function, and then are separated by a comma (,) and then the code of the function to be performed by this function.
Example:
Code example:
Related free learning recommendations:javascript video tutorial
The above is the detailed content of How to create javascript dynamic function. For more information, please follow other related articles on the PHP Chinese website!