Use cases for WeakMap
erik.corry at gmail.com
Sun May 15 14:20:32 PDT 2011
On May 15, 2011 8:59 AM, "Mark S. Miller" <erights at google.com> wrote:
> On Sat, May 14, 2011 at 11:57 PM, Erik Corry <erik.corry at gmail.com> wrote:
>> On May 15, 2011 2:55 AM, "Boris Zbarsky" <bzbarsky at mit.edu> wrote:
>> > On 5/14/11 6:37 PM, Oliver Hunt wrote:
>> >> Can you provide a use case where you have an object key as the usual
>> > Attaching metadata to object without polluting the objects themselves.
>> That sounds more like private names
> Private name and soft field lookup inherits. WeakMap lookup doesn't.
In rhe case where you care about this you can use hasOwnProperty.
And I think you should be able to add private properties to frozen objects.
Since the properties are private they are invisible to whoever froze the
object so they can't violate the expectations of the freezer. Perhaps it
also needs to be possible to freeze individual private properties (or their
absence) but being able to put a blanket ban on other parts of the program
performing an action that is undetectable to you feels wrong.
In terms of implementation this is no worse than keying a weak map with a
frozen object since that will also involve modifying the frozen object.
>> > For example, Firefox extensions want to do this all the time for
various DOM objects (and especially Window).
>> > -Boris
>> > _______________________________________________
>> > es-discuss mailing list
>> > es-discuss at mozilla.org
>> > https://mail.mozilla.org/listinfo/es-discuss
>> es-discuss mailing list
>> es-discuss at mozilla.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss