We all know that Javascript has two Function-defining methods that are very common. For example
Function a () {alert ("a")} var a = function () {alert ("")}
In javascript, any Function is a Function object. One is called implicit creation and the other is display creation,
What is "display creation" is to write a keyword "NEW". (This is not a scientific understanding.) For example:
Var test = new Function (cs1, cs2 .... CsN, function-body)
Note that cs1, cs2.. indicates the parameter, and function-body indicates the function body. You can call this function by using the variable name of the function object. You can call test (cs1, cs2…) in this way ...), Or assign a value to a variable, which can be called.
Var test = new Function ("cs1", "cs2", "alert (cs1 + cs2)"); test (1, 2 );
The effect is equivalent to our implicit creation.
Function test (cs1, cs2) {alert (cs1 + cs2);} test (1, 2) // var test1 = test; // test1 (1, 2 );
Therefore, when you use an implicit object, you must consider that it is a Function object created using the new keyword,
Alert (test. toString ());
You can output the code of the function body.
In addition, we usually use an anonymous function to create a function.
Var test = function (cs1, cs2) {alert (cs1 + cs2);} test (1, 2 );
The effect is equivalent to the creation of the display. Since the created function variable is an object, we can add new attributes and methods to the variable, in our js, the method is a special attribute, which requires attention.
Test. love = "I love php"; alert (test. love); test. php = function (msg) {alert (msg);} test. php ("how to study php! ");