Private symbols vs property attributes
David Bruant
bruant.d at gmail.com
Sun Feb 10 09:30:20 PST 2013
Le 10/02/2013 17:16, Mark S. Miller a écrit :
> I do not understand what is being proposed. When I try to imagine a
> proposal starting from what has been said, I have not been able to
> imagine something that works. But that's not a criticism. What is this
> alternate privacy idea?
My understanding is:
* there is only one kind of symbol
* whether the symbol is reflected by Object.getOwnPropertyNames and the
likes is controlled by a 'private' attribute in property descriptors.
// unique constructor, no boolean since there is only one kind of
symbol
var s = new Symbol();
var o = {}, o2 = {};
Object.defineProperty(o, s, {value: 12, private: true});
assert(Object.getOwnPropertyNames(o).length === 0)
assert(o[s] === 12);
o[s] = 31;
assert(o[s] === 31);
Object.defineProperty(o2, s, {value: 7, private: false});
assert(Object.getOwnPropertyNames(o)[0] === s);
assert(o2[s] === 7);
o2[s] = 13;
assert(o2[s] === 13);
Pending question:
var o3 = {};
o3[s] = 62;
Object.getOwnPropertyDescriptor(o3, s).private // true or false?
Since private:false implies symbol sharing through
Object.getOwnPropertyDescriptor, I think private:true should be favored
to force people to be explicit (see my reply to Brendan)
The main difference with the current proposal is that privacy isn't an
inherent characteristic of the symbol, but related to how it's been
configured on the different objects it's been used on.
Was the above one of the things you imagined? If yes, why doesn't it work?
David
More information about the es-discuss
mailing list