Skip to content

Instantly share code, notes, and snippets.

@bryanberger
Last active December 13, 2015 22:09
Show Gist options
  • Save bryanberger/4982719 to your computer and use it in GitHub Desktop.
Save bryanberger/4982719 to your computer and use it in GitHub Desktop.
Simple Module Export - Supports require.js defining of jQuery into the module.
//
// more documentation on the module pattern here: http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
//
(function( factory ) {
// if require js is available use it to define jquery and require it.
if (typeof define !== 'undefined' && define.amd) {
define(['jquery'], factory);
} else if (typeof module !== 'undefined' && module.exports) {
var jQuery = require('jquery');
module.exports = factory( $ );
} else {
window.testframework = factory( $ );
}
})(function( $ ) {
/* Exported Properties */
var exports = {};
exports.foo = 'bar';
/* Private Methods */
function privateMethod() {
console.log('a private method');
}
/* Exported Methods */
exports.publicMethod = function() {
console.log('a publicly exported method');
}
return exports;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment