Skip to content

Instantly share code, notes, and snippets.

@binzeehale
Last active August 29, 2015 14:10
Show Gist options
  • Save binzeehale/0598756042175d4ef0c6 to your computer and use it in GitHub Desktop.
Save binzeehale/0598756042175d4ef0c6 to your computer and use it in GitHub Desktop.
The write way for require/common/globally javascript lib
(function(name, definition) {
if (typeof module != 'undefined') module.exports = definition();
else if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
else this[name] = definition();
}('mod', function() {
//This is the code you would normally have inside define() or add to module.exports
return {
sayHi: function(name) {
console.log('Hi ' + name + '!');
}
};
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment