WeakMap API questions?
erik.arvidsson at gmail.com
Sat Aug 14 15:12:53 PDT 2010
Thanks for the answers Mark.
On Sat, Aug 14, 2010 at 14:01, Mark S. Miller <erights at google.com> wrote:
> On Fri, Aug 13, 2010 at 11:22 PM, Erik Arvidsson <erik.arvidsson at gmail.com>
>> I have a few questions regarding the WeakMap API.
>> 1. Why isn't there a way to check for presence of a key (using
>> Given that undefined is a valid value it is not sufficient to just
>> return undefined for get
> Simplicity without loss of generality. The example at
> shows how to build a WeakMap-like API as a thin layer on WeakMaps that
> implements the four method API you have in mind.
> Of course, layering this the other way would work too. Since both are
> plausible, it seems a better layering to have the primitive abstraction be
> the simpler one.
> Semantically, the way to understand the simpler API is that each WeakMap
> starts out as a mapping from all possible object identities to undefined.
> Thus, they only need to record those cases that map to something other than
I agree that your proposed API is the minimal API needed to build
useful abstractions on top of WeakMaps but I'm very concerned about
usability, code reuse and latency. I would hate to see Dojo, jQuery,
Prototype, Closure, YUI etc all providing their own slightly
incompatible wrappers around WeakMap.
More information about the es-discuss