0

I see that in many modules for node.js and also for browser, they use to have all their code inside something like this:

(function () {

  moduleName.prototype.variable = 'whatever';

})();

Can anyone please explain what this all is, or any links that explain? I have no idea how to search it! Thanks in advance.

john smith
  • 541
  • 6
  • 24
  • 2
    This is a pattern called [*Immediately Invoked Function Expression*](http://benalman.com/news/2010/11/immediately-invoked-function-expression/) – Arnaud Le Blanc Aug 22 '13 at 18:29

1 Answers1

1

This is a pattern called Immediately Invoked Function Expression.

It's mostly useful for isolation purposes.

Arnaud Le Blanc
  • 98,321
  • 23
  • 206
  • 194