_javascript techniques for famous functions and nameless functions in JavaScript

Source: Internet
Author: User

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");
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.