See Example: 1
Copy Code code as follows:
function A () {
Alert ("I am a cloud-dwelling community");
}
2
Copy Code code as follows:
var a = function () {
Alert ("I am a cloud-dwelling community");
}
The method of 1 and 2 is equivalent, 1 is a well-known function, and 2 is just a variable pointing to a nameless function, and 1 and 2 are equivalent here. 2 You can directly add parentheses after a function declaration to indicate that a function call is made immediately after the creation completes. For example:
var i = function (obj) {
alert (obj);
("I am a cloud-dwelling community");
Another important difference between a well-known function and a nameless function: For a well-known function, it can appear to be defined after the call, and for the nameless function, she must have been defined before the call. For example, the following error example uses a nameless function:
I ();
var i = function () {
Alert ("I am a cloud-dwelling community");
}
Here's how to do it correctly:
var i = function () {
Alert ("I am a cloud-dwelling community");
}
I ();
Or use a well-known function:
I ();
function I () {
Alert ("I am a cloud-dwelling community");
}