New private names proposal

David-Sarah Hopwood david-sarah at
Tue Dec 21 11:43:32 PST 2010

On 2010-12-21 08:49, Lasse Reichstein wrote:
> On Thu, 16 Dec 2010 23:19:12 +0100, Mark S. Miller <erights at> wrote:
>> On Thu, Dec 16, 2010 at 1:58 PM, Kris Kowal <kris.kowal at> wrote:
>>> On Thu, Dec 16, 2010 at 1:53 PM, David Herman <dherman at> wrote:
>>> >
>>> > 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 "" in the
> scope of "private foo", and "this[]".

That's not correct in general, since '' is first-class. (The specific
case "expr[]" is more easily optimizable without type inference, but
that's a case in which the #. syntax need not have been used.)

> The "gensym" syntax requires runtime checks to recognize that _x is a non-string
> property name.

Any expr[p] lookup needs a check for whether p is a string, when that cannot
be determined by type inference. The check that it is a private name or
soft field when when it is not a string is on the infrequent path, so will
not significantly affect performance.

>> Currently is JS, x['foo'] and 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 (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 "[".

If we're going to add an operator specifically for private lookup, we only
need one, for example:

function Point(x, y) {
    var x = SoftField(), y = SoftField();
    this.#x = x;
    this.#x = y;

(i.e. 'MemberExpression .# PrimaryExpression' or alternatively
'MemberExpression [ # Expression ]')

David-Sarah Hopwood  ⚥

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 292 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the es-discuss mailing list