JavaScript immediately called function expression N notation (second article)

Source: Internet
Author: User

Original: JavaScript immediately invokes the function expression n type of notation (second article)

  Previous blog I talked about converting a function declaration to a function expression the most common way to do this is to convert an anonymous function declaration to a function expression by using parentheses () (function () {}) ();

The implication is there are other ways, remember: any elimination of the function declaration and the ambiguity between function expressions can be correctly recognized by the parser! They can be divided into 5 categories, more than 10 kinds:

(function(){})();//The most common way to do this is to refer to it without any special indication.(function(){});//easily confused with the above[function()()];//Unary Operators~function(){};+function(){};-function(){};!function(){};//common in some 3rd party code//Key WordsDelete function() {}();typeof function() {}();void function() {}();New function() {}();New function() {};varf =function() {}();1,function() {}();0?function() {}();1 >function() {}();1 &&function(){}();
//...

Of course, they also have performance differences: New is always the slowest, +--at chrome speed amazing, common () and! The performance in each browser is also superior, plus +-one character less than ().

  FAQ : We may often see some plugins preceded by A; semicolon, which I understand as follows:

Glue ()

plugin (function() {//..... preceding should add; semicolon }) ();
Uncaught typeerror:undefined is not a function

The glue () function and plug-in execution are not error-free, but when glue () is combined with the plugin in some way, it will get an incorrect message. So we can write this:

;(function() {// omit a piece of Code }); --------------------------;! function () {// omit a piece of Code } (); ---------------------------; +function() {// omit a piece of Code } (); ----------------------------// et cetera

The above learning can be used as a force (~><~), at the same time will never understand the code of others and worry about!

JavaScript immediately invokes the function expression N notation (second 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.