Skip to content

Instantly share code, notes, and snippets.

@akloboucnik
Created May 24, 2012 12:39
Show Gist options
  • Save akloboucnik/2781348 to your computer and use it in GitHub Desktop.
Save akloboucnik/2781348 to your computer and use it in GitHub Desktop.
CoffeeScript namespace 101
namespace = (target, name, block) ->
[target, name, block] = [(if typeof exports isnt 'undefined' then exports else window), arguments...] if arguments.length < 3
top = target
target = target[item] or= {} for item in name.split '.'
block target, top
namespace '', (exports, root) -> root.namespace = namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment