Skip to content

Instantly share code, notes, and snippets.

@joscha
Last active December 17, 2015 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joscha/5657478 to your computer and use it in GitHub Desktop.
Save joscha/5657478 to your computer and use it in GitHub Desktop.
Factory pattern for CommonJS, AMD and Browser
((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