All I Want for Christmas: Effective JavaScript — Book Giveaway

Gah! Douglas Crockford has infected my brain on how invoking the function is preferable to invoking the parenthesis.

(function () {
  //add your magic here
}()); // good - the function is being invoked
(function () {
  //add your magic here
})(); // bad, this is trying to invoke the surrounding parenthesis

Also with the good example, the surrounding parenthesis make it clear that the function is not your standard one, and is inside the parenthesis in order to turn it in to a function expression.

It’s made nice and clear in his Programming Style & Your Brain @27:28 video, and I highly recommend rewinding from that spot to enjoy the rest of his talk too.

1 Like