Skip to content

Instantly share code, notes, and snippets.

@shotamatsuda
Created December 28, 2016 15: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 shotamatsuda/20850b19c6b6737672a0c40301f93fc8 to your computer and use it in GitHub Desktop.
Save shotamatsuda/20850b19c6b6737672a0c40301f93fc8 to your computer and use it in GitHub Desktop.
export function Namespace(name) {
const symbol = Symbol(name)
return function namespace(object, init = () => ({})) {
if (object[symbol] === undefined) {
object[symbol] = init()
}
return object[symbol]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment