Skip to content

Instantly share code, notes, and snippets.

@k-maru
Created October 14, 2017 22:58
Show Gist options
  • Save k-maru/1cfeb077d29a9ab269e2b8b5f81f4520 to your computer and use it in GitHub Desktop.
Save k-maru/1cfeb077d29a9ab269e2b8b5f81f4520 to your computer and use it in GitHub Desktop.
private member for js
import ns from "./namespace";

const internal = ns();

class ClassName {

    constructor() {
        
        internal(this).userName = "Foo";
        let userName = internal(this).userName;
        
    }

}
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