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)