Skip to content

Instantly share code, notes, and snippets.

@esamattis
Last active January 29, 2016 13:29
Show Gist options
  • Save esamattis/1267261 to your computer and use it in GitHub Desktop.
Save esamattis/1267261 to your computer and use it in GitHub Desktop.
Simple namespace tool
# 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