Created
December 16, 2014 13:27
-
-
Save jamesnicholls/086aaf41d55e2ba265ac to your computer and use it in GitHub Desktop.
Multi-environment module pattern
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
// function will execute immediately | |
(function(root, factory) { | |
if (typeof exports === 'object') { | |
// commonjs | |
module.exports = factory( | |
// pass dependencies via require | |
); | |
} else if (typeof define === 'function' && define.amd) { | |
// amd | |
define([ | |
// dependencies go here | |
], factory); | |
} else { | |
// browser | |
// expose variable as property of window | |
root.foo = factory( | |
// pass dependencies here | |
// Dependencies should have already been included via script tags and exposed as properties of window | |
); | |
} | |
}) | |
(this, function() { | |
// module code goes here | |
// any dependencies should be passed in as arguments | |
// return the symbol to expose | |
return; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment