Location of parenthesis for auto-executing anonymous JavaScript functions?

前端 未结 4 1979
离开以前
离开以前 2020-11-21 06:57

I was recently comparing the current version of json2.js with the version I had in my project and noticed a difference in how the function expression was created and self ex

4条回答
  •  醉话见心
    2020-11-21 07:11

    In that case it doesn't matter. You are invoking an expression that resolves to a function in the first definition, and defining and immediately invoking a function in the second example. They're similar because the function expression in the first example is just the function definition.

    There are other more obviously useful cases for invoking expressions that resolve to functions:

    (foo || bar)()
    

提交回复
热议问题