标签云

微信群

扫码加入我们

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年09月24日16分53秒

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年09月25日16分53秒

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

2018年09月24日16分53秒

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

2018年09月24日16分53秒

Thanks, I updated it.

2018年09月24日16分53秒

I update my answer too :)

2018年09月24日16分53秒