Created
October 27, 2015 07:26
-
-
Save yumitsu/66e04aaae1a2ca064931 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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