Skip to content

Instantly share code, notes, and snippets.

@mweppler
Created April 30, 2013 16:11
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 mweppler/5489730 to your computer and use it in GitHub Desktop.
Save mweppler/5489730 to your computer and use it in GitHub Desktop.
do () ->
namespacer = (ns, obj) ->
if not typeof ns == "string" or not ns.length
throw new Error '[namespacer] Invalid namespace'
namespace = @
namespace = namespace[part] = namespace[part] or {} for part in ns.split '.'
namespace[attr] = obj[attr] for attr of obj if typeof obj == 'object'
namespace
@['namespacer'] = @['ns'] = namespacer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment