What is (function(){})()?

I just found this function, which confuses me. Here is the example:

Capture.1234PNG

Result:

Capture1234

Looks like a little bit complex. But i will change to another classic example:

1.PNG

This function means, immediately-Invoked Function Expression(自执行匿名函数) or IIFE. It executes immediately after it created.

In the first parenthesis (), it means an anonymous function(匿名函数), the second parenthesis, it calls this anonymous function and  parses param(调用并传入参数).

11

For example, in the second parenthesis (), 2 and 3 are param. After created this function, it would execute immediately.

Meanwhile, one thing needs to be mentioned,

Capture

this one is not immediately invoked function expression, but an shorter method for document ready event.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s