import ns from "./namespace";
const internal = ns();
class ClassName {
constructor() {
internal(this).userName = "Foo";
let userName = internal(this).userName;
}
}
Created
October 14, 2017 22:58
-
-
Save k-maru/1cfeb077d29a9ab269e2b8b5f81f4520 to your computer and use it in GitHub Desktop.
private member for js
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 default function namespace(){ | |
const map = new WeakMap(); | |
return (obj) => { | |
if (!map.has(obj)) { | |
map.set(obj, {}); | |
} | |
return map.get(obj); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment