1

I've noticed that Google Closure Compiler seems to use both interchangeably.

1.

(function a() {
  window.requestAnimationFrame(function() {
    //
    a();
  });
})();

2.

(function a() {
  window.requestAnimationFrame(function() {
    //
    a();
  });
}());

1 Answers1

1

There is no one "closure syntax" : any syntax ensuring you build a function expression, that is a function expression that the compiler can't confuse with the start of a function definition, and you call it is OK. Here, both work.

You could for example have used

+function(){
  ...
}();

Simply choose the one that is the most readable and the less surprising. I think the first one, in which the call parenthesis are the most visible, is the most used and expected.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758