标签云

微信群

扫码加入我们

WeChat QR Code

I see a piece of JavaScript code in my Node.js application.

( function() { console.log("gg") } )(this)

I would like to know why use => ( function(){} )(this) this type of structure, and how does this compile.

I am understanding why we have this two brackets ()(), and why this code would work.


Ok, the interesting thing is though, why (this) is passed?!?

2018年07月17日06分40秒

I want to know too

2018年07月17日06分40秒

How about (function(){})(this); Does "this" invoke this function? How about (function(global, requirejs, require){})(this, requirejs, require) ?

2018年07月17日06分40秒

these are just additional parameters which you can pass to the given function I'll fix this in my answer

2018年07月18日06分40秒

i think this explains everything you need to know link

2018年07月17日06分40秒