WeakMap API questions?
Mark S. Miller
erights at google.com
Sat Aug 14 15:49:41 PDT 2010
On Sat, Aug 14, 2010 at 3:12 PM, Erik Arvidsson <erik.arvidsson at gmail.com>wrote:
> 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>
> > wrote:
> >> I have a few questions regarding the WeakMap API.
> >> 1. Why isn't there a way to check for presence of a key (using
> >> has/contains)?
> >> 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
> > 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
> > undefined.
> 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.
I agree that it makes perfect sense to standardize some derived abstractions
as well, including an explicit form of Inherited Soft Fields <
Although these should be specified as wrapper implementations, this one in
particular could probably perform much better if it were implemented
primitively. Standardizing these derived abstractions enables them to be
primitively provided across browsers in like manner.
I have created strawman page <
to suggest that this addition be promoted to proposal.
John & Istvan, could you add this to the agenda for our next meeting?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss