23maverick23
12/1/2013 - 9:36 PM

JavaScript: JS library boilerplate code examples

JavaScript: JS library boilerplate code examples

/**
 * This is an example of an "immediately-invoked function expression" or IIFE which is a common
 * pattern in JavaScript.This pattern creates a function expression and then immediately executes
 * the function. This pattern is extremely useful for cases where you want to avoid polluting the
 * global namespace with code – no variables declared inside of the function are visible outside of it.
 * 
 * This example also applies what Paul Irish calls the "ass hole case", by also correctly assigning the
 * value of "undefined" to an undefined value (which prevents ass holes from overriding that on the page).
 * 
 * [link](http://code.tutsplus.com/tutorials/10-things-i-learned-from-the-jquery-source--net-12367)
 */

(function (window, document, undefined) {
    
    // ...
    
})(this, document);
/**
 * JavaScript library boilerplate - useful when creating standalone JS libraries.
 * [link](http://net.tutsplus.com/tutorials/javascript-ajax/build-your-first-javascript-library/)
 */

window.dome = (function () {
   function Dome (els) {
       
   }
    
   var dome = {
      get: function (selector) {
       
      }  
   };
    
   return dome;
}());