Created
February 28, 2014 18:22
-
-
Save robatron/9276675 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** Example module that supports CommonJS and IFFE modularity | |
* | |
* - CommonJS modules can be imported via `require` | |
* - IFFE modules attach themselves to the browser's window object | |
*/ | |
;( function ( factory ) { | |
// If the environment supports CommonJS modules, attach module to `module.exports` | |
if ( typeof require === 'function' && typeof exports === 'object' && typeof module === 'object' ) { | |
var target = module.exports || exports; | |
factory( target ); | |
// Otherwise, attach module to the window | |
} else { | |
window.myModule = {}; | |
factory( window.myModule ); | |
} | |
}( function ( target ) { | |
// Exposed module | |
target.foo = 'bar'; | |
// ... | |
} ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment