What are the differences between these three types of module pattern?

后端 未结 3 1092
遥遥无期
遥遥无期 2020-12-21 03:57
1)function () { 
    // code here...

}();

2)(function () { 
    // code here...

})();



3)(function () { 
    // code here...

}());

What are t

3条回答
  •  暖寄归人
    2020-12-21 04:46

    2 and 3 are exactly equivalent. There is no functional difference between them.

    1 is a syntax error. Because the function is not wrapped in brackets, it is treated as a function declaration. It is invalid because function declaration need to be named. The brackets make it a "function expression"; these do not need to be named.

提交回复
热议问题