On Thu, 16 Dec 2010 23:19:12 +0100, Mark S. Miller <[email protected]>
wrote:
On Thu, Dec 16, 2010 at 1:58 PM, Kris Kowal <[email protected]> wrote:
On Thu, Dec 16, 2010 at 1:53 PM, David Herman <[email protected]>
wrote:
>
> function Point(x, y) {
> private x, y;
> this.x = x;
> this.y = y;
> ...
> }
>
> than
>
> function Point(x, y) {
> var _x = gensym(), _y = gensym();
> this[_x] = x;
> this[_y] = y;
> }
I tend to disagree with most developers, so take it with a grain of
salt that I find the latter form, with all the implied abilities,
easier to understand.
I do too. While terseness clearly contributes to understandability,
regularity and simplicity do too. When these conflict, we should be very
careful about sacrificing regularity.
While I dislike the "private" syntax just as much, it does have the
advantage
of being statically detectable as using a private name, both "this.foo" in
the scope
of "private foo", and "this[#.foo]".
The "gensym" syntax requires runtime checks to recognize that _x is a
non-string
property name.
Currently is JS, x['foo'] and x.foo are precisely identical in all
contexts.
This regularity helps understandability. The terseness difference above
is not an adequate reason to sacrifice it.
Agree. I would prefer something like x.#foo to make it obvious that it's
not the
same as x.foo (also so you can write both in the same scope), and use
"var bar = #foo /* or just foo */; x[#bar]" for computed private name
lookup. I.e. effectively introducing
".#", "[#" as alternatives to just "." or "[".
I'm not sure it's better to use an operator to reify the private name
("#foo") or it being directly
denotable ("foo") in an expression context. Both can be used.
In the latter case, x.#foo and x[#foo] would be equivalent.
/Lasse
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss