What is the difference between these 2 JavaScript declarations?

后端 未结 5 1396
执念已碎
执念已碎 2021-01-02 05:10

For one of them the \"()\" is inside, for the other one it is outside. Here they are:

var a = (function() {
    return {
        bla: function(         


        
5条回答
  •  误落风尘
    2021-01-02 05:44

    There is no practical difference, it's just a subtle difference in how you make the Javascript engine think of the function as a value.

    Using ( function(){} () ); you are causing the function to be a value because a statement can't start with a parenthesis. Using ( function(){} ) (); you are using the parentheses to first evaluate the function as a value, then call it.

提交回复
热议问题