<分区>
下面的 JavaScript 闭包函数的外部额外括号的目的是什么?我在其他帖子中被告知它们不是绝对必要的,但它们是一种约定,以明确传递的是函数的结果,而不是函数本身。以下引自http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html 但是,冲突。哪个是正确的?
Notice the () around the anonymous function. This is required by the language, since statements that begin with the token function are always considered to be function declarations. Including () creates a function expression instead.
(function () {
// ... all vars and functions are in this scope only
// still maintains access to all globals
}());