Skip to content

Instantly share code, notes, and snippets.

@yumitsu
Created October 27, 2015 07:26
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 yumitsu/66e04aaae1a2ca064931 to your computer and use it in GitHub Desktop.
Save yumitsu/66e04aaae1a2ca064931 to your computer and use it in GitHub Desktop.
window.namespace = ->
args = arguments[0]
target = global || window
loop
for subpackage, obj of args
target = target[subpackage] or= {}
args = obj
break unless typeof args is 'object'
Class = args
target = window if arguments[0].hasOwnProperty 'global'
name = if !Class.name? # IE Fix
args.toString().match(/^function\s(\w+)\(/)[1]
else
Class.name
proto = target[name] or undefined
target[name] = Class
if proto?
for i of proto
target[name][i] = proto[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment