Skip to content

Instantly share code, notes, and snippets.

@peb7268
Created November 18, 2012 18:26
Show Gist options
  • Save peb7268/4106658 to your computer and use it in GitHub Desktop.
Save peb7268/4106658 to your computer and use it in GitHub Desktop.
JavaScript: Module Augmentation
/*** A Better way with the module pattern ******************************************************************************#/
* Our goals:
*
* 1) We define a module and scope it within a self invoking anonymous function
* 2) We perform a global import (by passing jQuery in as a param) and namespace it so we circumvent naming collisions
* 3) We then export the module with the return keyword
************************************************************************************************************************/
var jQuery = (function($){
//private vars
$.someNewProperty = 'booyah';
//New Super Duper Method
$.superDuperMethod = function(message){
console.log('Im a new super duper method that says: ' + message);
}
return $;
})(jQuery);
//Implementation
$(document).ready(function(){
$.superDuperMethod('Whhhaaasssssuuuppppp!!!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment