Skip to content

Instantly share code, notes, and snippets.

@vitorbal
Forked from bryanberger/simplemoduleexport.js
Last active December 14, 2015 01:28
Show Gist options
  • Save vitorbal/5005905 to your computer and use it in GitHub Desktop.
Save vitorbal/5005905 to your computer and use it in GitHub Desktop.
Exporting pattern for scripts that supports both AMD and Node module patterns. Exports to `window` as a fallback.
(function( factory ) {
// if require js is available use it to define jquery and require it.
if ( typeof define === 'function' && define.amd ) {
define( ['jquery'], factory );
} else if ( typeof module !== 'undefined' && module.exports ) {
var jQuery = require('jquery');
module.exports = factory( $ );
} else {
window.YourModule = 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