Last active
January 29, 2016 13:29
Simple namespace tool
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
# Namespace tool for accessing our namespace | |
# | |
# Usage: | |
# bar = NS "PWB.foo.bar" | |
# | |
# Idea from Javascript Patterns by Stoyan Stefanov | |
# | |
window.NS = (nsString) -> | |
parent = window | |
for ns in nsString.split "." | |
# Create new namespace if it is missing | |
parent = parent[ns] ?= {} | |
parent # return the asked namespace |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment