Summary of function declaration in javascript

Source: Internet
Author: User

Function test (){
Return 123;
}


Obviously, this is a function declaration. What about the following?
Var B = function () {return 123 };


We suspect that this is not a declaration. Because the function has no name, it is just an anonymous function. Well, let's look at it again.
Var B = function test () {return 123 };


Is this a function declaration? It seems like, then I will answer you, "no"
Alert (test );
Var B = function test () {return 123 };


You can test any js implementation on non-ie, and the test undefined error will be reported. What if so?
Var B = function test () {return 123 };
Alert (B );
Alert (test );


Function test () {...} is displayed (){...} the toString result of this function can be the second alert or exception. Why? That is to say, function test () {return 123} is not a declaration, but a function object, put the reference in B, so the function object will not be bound to the test name by default like the declaration. Why don't I use ie for testing?
Alert (test );
Var B = function test () {return 123 };


Ie will display the function. ie is stupid and will not distinguish between the independent function declaration and the function object on the right. In addition, ie even supports function String. prototype. test (){...} such a statement shows that there are quite a few js bugs in ie. It is no wonder that wilson does not support es4. He has to make an es3.1 release. It is actually his own bug correction version.

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.