Created
April 20, 2015 17:59
-
-
Save zachwolf/f254aed57a0fc65bb3b2 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
let Foo = (function () { | |
let __secrets = new WeakMap(); | |
class Foo { | |
constructor () { | |
__secrets.set(this, Math.floor(Math.random()*100)); | |
} | |
get bar() { | |
return __secrets.get(this); | |
} | |
} | |
return Foo;// (() => new Foo())() | |
}()); | |
console.log(new Foo().bar); | |
console.log(new Foo().bar); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on http://sravi-kiran.blogspot.com/2015/01/PrivateMembersInES6Classes.html