Rick Waldron (2014-01-08T22:24:05.000Z)
On Wed, Jan 8, 2014 at 3:59 AM, Maciej Jaros <egil at wp.pl> wrote:

> To my understanding private name objects are supposed to make private
> properties and functions available for new classes syntax in ECMAScript 6
> standard.
>
> But the syntax is rather strange:
> ```
> var myPrivate = new Name();
> class Test {
>      constructor(foo) {
>           this[myPrivate] = foo;
>      }
> }
> ```
>
>
Private names were replaced by the not-private Symbol. Symbol is a symbol,
private if you keep it that way and public if you expose it.



> I understand the motivation - using just `this[myPrivate]` wouldn't work
> because it could be inconsisten when `myPrivate` is a string variable.


Symbol produces symbols, not strings.


> If `myPrivate='abc'` then `this[myPrivate]` is equivalent `this.abc`... So
> that is the main reason Name objects were born, right?
>

If the symbol was used to create the property, and the binding undergoes a
reassignment, the property won't be accessible via property access by
bracket notation:

var o = {};
var s = Symbol();

o[s] = 1;
o[s];
// 1

s = "s";
o[s];
// undefined


You could still get the Symbol by Object.getOwnPropertySymbols(o)... again
there is no implied privacy with Symbols.


Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140108/a844ae7f/attachment.html>
domenic at domenicdenicola.com (2014-01-09T16:44:36.143Z)
On Wed, Jan 8, 2014 at 3:59 AM, Maciej Jaros <egil at wp.pl> wrote:

> To my understanding private name objects are supposed to make private
> properties and functions available for new classes syntax in ECMAScript 6
> standard.
>
> But the syntax is rather strange:
>
> ```js
> var myPrivate = new Name();
> class Test {
>      constructor(foo) {
>           this[myPrivate] = foo;
>      }
> }
> ```

Private names were replaced by the not-private Symbol. Symbol is a symbol,
private if you keep it that way and public if you expose it.



> I understand the motivation - using just `this[myPrivate]` wouldn't work
> because it could be inconsisten when `myPrivate` is a string variable.


Symbol produces symbols, not strings.


> If `myPrivate='abc'` then `this[myPrivate]` is equivalent `this.abc`... So
> that is the main reason Name objects were born, right?
>

If the symbol was used to create the property, and the binding undergoes a
reassignment, the property won't be accessible via property access by
bracket notation:

```js
var o = {};
var s = Symbol();

o[s] = 1;
o[s];
// 1

s = "s";
o[s];
// undefined
```

You could still get the Symbol by `Object.getOwnPropertySymbols(o)`... again
there is no implied privacy with Symbols.