>> this[private(MyClass, "pwd")] = pwd;
>
> You just reified, in the square brackets.
True, but I didn’t introduce a variable with a scope (see below for more
detailed arguments).
> Worse, you seem to make it possible for anyone with access to MyClass to pass
> a string into this private pseudo-function (I hope it cannot be passed around
> as a funarg!) and get out the reified private name!
>
> If you mean only for the private(C,id) form to be valid in [], then surely we
> should be talking about shorter and less special and wrongly general-looking
> syntax, e.g. infix @.
Absolutely, the syntax was 100% strawman. I’d expect it to be highly optimized
behind the scenes (to be treated like a literal by a compiler) and to be
replaced by syntax that looks much better, e.g.:
this.MyClass@pwd = pwd;
> With the current proposal, you can do something like this:
>
> {
> import create from "@name";
> const pwdName = create("pwd");
> function MyClass(pwd) {
> this[pwdName] = pwd;
> }
> MyClass.prototype.isPwd = function(pwd) {
> return this[pwdName] === pwd;
> }
> }
>
> It might be too verbose to have to import create from "@name" and call it. We
> can address that with sugar or shorter API design. But that's not what you
> were addressing.
Yes, as it stands, the proposal is quite usable. You can even export pwdName to
unit tests (which would make more sense if it was a method identifier). I only
wish we could avoid redundantly repeating private names, usually far away from
where they are actually used. I like that this approach can be retrofitted so
easily, but suspect that having to “declare” each private name before using it
will get tired quickly.
--
Dr. Axel Rauschmayer
[email protected]
twitter.com/rauschma
home: rauschma.de
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss