WeakMap API questions?
erik.corry at gmail.com
Thu Sep 2 11:32:43 PDT 2010
2010/9/2 Mike Shaver <mike.shaver at gmail.com>:
> On Thu, Sep 2, 2010 at 12:46 AM, Erik Corry <erik.corry at gmail.com> wrote:
>> And this is as it should be. As it stands the weak map can be used as
>> an object with private members. The object key acts as a capability
>> that controls whether or not you have access to the private member.
> If I were to be using an object with private members, I would
> certainly expect that those members would keep their values alive.
Surely that is the case with WeakMap? At least unless you lost the
key and don't have any other references to the value. In which case
you can't reach the value any more, so why would you care whether it
is kept alive?
> Wouldn't it be better to just use a regular object, and add private
> members via defineProperty to make them non-enumerable?
That is certainly a fine way to do private members if they only need
to be private by convention and there are no security issues around
them being private.
> I'm not in favour of WeakMap enumerability, really, but it seems that
> there's an easier way to address this particular use case.
More information about the es-discuss