开发者

How is this parsed by the Javascript lexer? (Closures-pattern without parens)

I've noticed this pattern of wrapping closures in parens ()

(function () 开发者_开发百科{
  var foo = 1;
  return function () {return foo}
}())

It raises the question, how is this supposed to be parsed:

function () {
  var foo = 1;
  return function () {return foo}
}()


The parentheses around the function are necessary, because when omitted, the compiler assumes it is a Function Statement.

Function statements are not invocable.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜