3 ms·
The point of it is you can implement private properties, as I understand it: function MyClass() { var mysymbol = new Symbol("foo"); this[my
by TazeTSchnitzel 12y ago
The point of it is you can implement private properties, as I understand it:
function MyClass() {
var mysymbol = new Symbol("foo");
this[mysymbol] = 3;
}
var bar = new MyClass();
bar.foo // this won't work
- Tloewald 12y agoWhat a convoluted mechanism!
- Tloewald 12y agoWhat a convoluted mechanism!
- Tloewald 12y agoWhat a convoluted mechanism! But where do you keep your reference to the symbol to keep it private? Anywhere you keep it (e.g. in a closure somewhere) that's private doesn't need symbols, so what problem does this solve? And surely in your private context, bar.foo should still work.