

How to: code JavaScript using Twitter bootstrap best practices - baptou12
http://www.theodo.fr/blog/2014/03/how-to-code-javascript-using-twitter-bootstrap-best-practices/

======
usablebytes
A cleaner way to convert a function declaration into a function expression
would be to use brackets

    
    
      (function() {
        //code here
      })();
    

This won't affect the return type of the statement; which in case of using !
will return boolean 'true' unless the function returns a truthy value. Plus
using ! for this purpose, looks totally messy.

~~~
tothepixel
To extend upon this, you can also pass in references to decrease lookup time.
That's why you see people doing:

    
    
       (function($,window) {
         //code here
       })(jQuery,window);

~~~
thekingshorses
This reduces size after uglifying.

    
    
      (function(window, $, otherGlobal) {  
         $ = window.jQuery;
         otherGlobal = window.otherGlobal;
    
         //code here
      })(window);

------
bpizzi
FYI, the blog post suggests that bootstrap is currently developped at twitter,
which is not the case anymore @see
[http://getbootstrap.com/about/](http://getbootstrap.com/about/)

~~~
bejonster
You're right. This has been corrected.

------
DrinkWater
"The ! converts the function declaration to a function expression" .... and i
closed the tab

~~~
cocoflunchy
There's a good discussion over here:
[https://github.com/airbnb/javascript/issues/44](https://github.com/airbnb/javascript/issues/44)

~~~
pjc50
Oh god. Javascript's optional semicolon really has inflicted a lot of damage,
hasn't it?

~~~
bshimmin
Horrible, isn't it? Baffling, quasi-random punctuation inserted to prevent
random errors caused by poor design choices intended to make programmers'
lives easier.

------
edfuh
protip: you will have a better time if you read this as satire.

------
myhf
Oh my, this isn't satire.

