> Maybe it could use more example use cases. What you're proposing above could 
> also be done by keeping the private value in a closure, but if you > need to 
> hang it off the object this gives you a way to do that safely.
Well yes a closure works if you want a value for an object... but as
soon as you start having several instances, you need to either not use
the prototype or do some some arrays and store values in them... and
it kind of sucks...

I still don't understand how the thing in the link you psoted works...
var s = {};
undefined
var o = {};
undefined
var o2 = {};
undefined
s[ o ] = 1;
1
s[ o2 ];
1


On Fri, Sep 30, 2011 at 5:17 PM, Dean Landolt <d...@deanlandolt.com> wrote:
>
>
> On Fri, Sep 30, 2011 at 10:14 AM, Xavier MONTILLET <xavierm02....@gmail.com>
> wrote:
>>
>> module name from "@name";
>> let key = name.create();
>> function MyClass(privateData) {
>>    this[key] = privateData;
>> }
>> MyClass.prototype = {
>>    doStuff: function() {
>>        ... this[key] ...
>>    }
>> };
>>
>> All it does is make the key a special string...
>
> No, the key is a special object...
>
>>
>> If you get the same string, you can still access the property...
>
> Because it's an object this is impossible, and it's guaranteed to be
> unforgeable.
>
>>
>> Plus, either you make it non-enumerable so that noone can find the key
>> which is annoying, or you can find the key with a simple for in
>> loop...
>
>
> There's a note about a possible "visibility flag" extension in there, but as
> it stands, no, it's not enumerable. The creator of the private name object
> is the one that doles out the capability to get to the value.
>
>>
>> I'm not sure I understand this proposal...
>
> Maybe it could use more example use cases. What you're proposing above could
> also be done by keeping the private value in a closure, but if you need to
> hang it off the object this gives you a way to do that safely.
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to