private name objects confusion

Dean Landolt dean at
Wed Jul 27 11:06:08 PDT 2011

I've been exploring private name objects [1] and I'm a bit confused by a few
things in the proposal, especially the Reflection example...

module Name = require "@name";
let o = { };
let name = Name.create("foo");
o[name] = "secret!";
...let a = Object.getOwnPropertyNames(o);for (let i = 0; i < a.length; i++) {
    if (a[i] === name.public)

The proposal defaults Name.create's visibility to false, so my first
assumption was it's not supposed to show up at all in
Object.getOwnPropertyNames(o) and it was just an oversight. But after
rereading it a few times this line keeps throwing me (emphasis added):

The visible argument determines whether the name is made *directly* visible
to reflection API‘s.

Another possible interpretation is that if the name is set to visible then
getOwnPropertyNames would contain the name object, otherwise it would
contain name.public. Another way to ask this, modifying the example

module Name = require "@name";
let o = { foo: "public!" };
let fooName = Name.create("foo");
o[fooName] = "secret!";

Should this statement return ["foo"] or ["foo", fooName.public]? And if
visibility were true:

module Name = require "@name";
let o = { foo: "public!" };
let name = Name.create("foo", true);
o[name] = "secret!";

Should this statement return ["foo", fooName.public] or ["foo", fooName]? If
the latter interpretation is correct, what advantage does a visible private
name have over a plain old non-enumerable property?

I also see no mention of what `str` should default to in Name.create, even
though it's defined as optional and is quite significant as the
name.public.toString return value. Is there something like a unique string
value planned for this? At the very least the proposal should hint at what
Name.create().public.toString() should return (assuming it's not undefined).

My apologies if some of this has been discussed -- the last I can find was
in the TC39 meeting notes from May:

Advanced to Harmony, with the big open issue of reflecting on private names.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list