Created
November 18, 2012 18:26
-
-
Save peb7268/4106658 to your computer and use it in GitHub Desktop.
JavaScript: Module Augmentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** 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