Created
December 28, 2016 15:26
-
-
Save shotamatsuda/20850b19c6b6737672a0c40301f93fc8 to your computer and use it in GitHub Desktop.
This file contains 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
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