The private names proposal has a lot of good ideas, but their use is
not obvious.
The reasons I see for that are:
The "private a;" declaration:
* changes meaning of all obj.a in scope
* looks like a scoped variable, not a private element of an object
* is not generative-looking
... which makes it harder to understand, and use.


I find that David Herman's proposal fixes those issues:
>But your idea suggests yet another alternative worth adding to our growing 
>pantheon. We could allow for the scoping of private names, but always require 
>them to be prefixed by the sigil. This way there's no possibility of mixing up 
>public and private names. So to use an earlier example from this thread 
>(originally suggested to me by Allen):
>
>   function Point(x, y) {
>       private #x, #y;
>       this.#x = x;
>       this.#y = y;
>   }

I understand that the number sign gets really heavy and annoying after
some time. As a result, I suggest a simpler syntax, "private
.secret;":

a = {};
k = {a: a};
a['k'] = k;
function aa(o) {
  private .a;
  k..a = o;  // or: private c.a; c.a = o;
  a.a = a.k.a;  // or: a['a'] = a['k']['a'];
  a.a = k..a;  // here, on the other hand, k.a is the private stuff.
  return .a;
}
let a2 = aa(a);
print( a[a2] === a );  // true

Would this syntax be less Perlish?



ps: my understanding is that, using the current specification,
print(a[a2] === a.k.a) from my earlier email yields true, not false,
since (a.k.a === a). Am I wrong?

On Wed, Dec 22, 2010 at 12:40 AM, Brendan Eich <[email protected]> wrote:
> a = {};
> k = {a: a};
> a['k'] = k;
>
> function aa(o) {
>  private a;
>  k.a = o;
>  a.a = a.k.a;
>  return #.a;
> }
>
> print(a[a2] === a.k.a);
>
> false
> Note that (a[a2] === a.k[a2] && a[a2] === a).
> This is all kind of plug-and-chug from my reading of the strawman. Was it
> unclear in a way where you could suggest a fix? Or maybe it just didn't
> start with a minimal statement of the rules.
> /be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to