0

It's very common nowadays for Javascript libraries / functions / code snippets to be encapsulated with an anonymous function, e.g.

(function () {
    // code to be executed goes here
})();

As far as I can tell, that should be completely superfluous: that anonymous function just executes the code within. However, there's obviously a reason behind this! :-)

I've seen an occurrence of this with a comment alongside the first line: "// function wrapper for Opera".

Does anyone know why this code is commonly used, what the history of its development is, and what the relation with Opera is?

Bobby Jack
  • 15,689
  • 15
  • 65
  • 97

0 Answers0