Skip to content

Instantly share code, notes, and snippets.

@rjsheperd
Last active August 29, 2015 14:17
Show Gist options
  • Save rjsheperd/85033cae27c09d445192 to your computer and use it in GitHub Desktop.
Save rjsheperd/85033cae27c09d445192 to your computer and use it in GitHub Desktop.
// Set up global May Day object (md) to attach functions to
var md = md || {};
(function($, md) {
// dollar sign ($) == jQuery
// Can add new functions to the jQuery prototype
$.fn.newFunction = function() {
return true;
}
// Can add functions to the global May Day object to be used later
md.helloWorld = function() {
return 'Hello World';
}
// Can also attach properties to the May Day object
md.senators = {
California: ['Boxer', 'Feinstein'],
};
//
$('#derp').on('click', function() {
var text = md.helloWorld;
console.log(text);
});
$.ready(function() {
alert('All systems are go');
});
})(jQuery, md);
// Mayday object is accessible outside of the module!
var hello = md.helloWorld();
if (md.senators.California[0] == 'Boxer') {
console.log('huzzah!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment