Thanks for the answers Mark. On Sat, Aug 14, 2010 at 14:01, Mark S. Miller <[email protected]> wrote: > On Fri, Aug 13, 2010 at 11:22 PM, Erik Arvidsson <[email protected]> > 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 > <http://wiki.ecmascript.org/doku.php?id=harmony:weak_maps#explicit_soft_own_fields> > 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 > 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. -- erik _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

