Last active
December 17, 2015 18:59
-
-
Save joscha/5657478 to your computer and use it in GitHub Desktop.
Factory pattern for CommonJS, AMD and Browser
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
((root, ns, factory) -> | |
'use strict' | |
# CommonJS | |
if typeof exports is 'object' and typeof module is 'object' | |
module.exports = factory() | |
# AMD | |
else if typeof define is 'function' and define.amd | |
define factory | |
# Browser | |
else | |
root[ns] = factory() | |
) (if typeof window is 'object' then window else @), 'myLib', -> | |
'use strict' | |
class X | |
foo: -> | |
console.log 'foo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment