开发者

What this mean in javascript? [duplicate]

This question already has answers here: 开发者_运维百科 Closed 12 years ago.

Possible Duplicate:

Explain JavaScript's encapsulated anonymous function syntax

I have just read a javascript book but I have seen this code:

1(function() {

          // code

})();

what is this ? is a special function ?


As written, it has a syntax error.

I'm guessing it was more like:

(function() {
          // code
})();

or

(function() {
          // code
    }
)();

Break it down:

(FOO)() // calls FOO with no arguments.

And

function() { //creates a function that takes no arguments.
      // code
}

Hence together it would create a function that takes no arguments, and then call it. I can't see why you would apart from just showing that you can.


It looks like the intent was to declare the function inline/anonymous and immediately execute it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜