标签云

微信群

扫码加入我们

WeChat QR Code

In the Google tutorial for implementing Google+ sign-in in Flask application, I discovered that the developer often uses an awkward way of executing JavaScript code:

Instead of doing

var a = foo(bar);

I see this:

var a = (function() {
  return foo(bar);
})();

What is the reason to do it the weird way?


can you provide direct example. it depends on the situation

2018年07月17日07分13秒

There's no reason to use that syntax there, and it doesn't appear on the page you link to. Could you link to the actual example so we can see the context?

2018年07月18日07分13秒

Oh, ok, so it's just not to leave garbage of once needed but now obsolete variables behind.

2018年07月17日07分13秒

Quentin the actual code in the tutorial is very large and thus too specific to be included in the question.

2018年07月17日07分13秒

Thanks, I updated it.

2018年07月17日07分13秒

I update my answer too :)

2018年07月18日07分13秒