I was looking at the jQuery plugins for Twitter Bootstrap and saw that they were all defined using a pattern like this:
!function($) { // code here // plugin definition here } ( window.jQuery || window.ender); This looks like a variation of the immediately executing anonymous function (anonymous closure):
(function($) { // code here }(jQuery)); Can someone explain what the Bootstrap variation does and why? Is this a better way to write an anonymous closure?
Thanks!
()helps avoid bugs like this one()to create an IIFE. The bug is a combination of JS only having function scope, having ASI, and overloading the()syntax. It's up to the individual developer as to how they want to deal with it. Inserting a semi-colon is one option.