Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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