WeakMap API questions?

Ash Berlin ash_js at firemirror.com
Sat Aug 14 13:01:45 PDT 2010

On 14 Aug 2010, at 07:22, Erik Arvidsson 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

Does the standard trick of:

  if (key in weakMapInstance) { }

not work?

> 2. Why isn't there a way to remove a key-value-pair?
> Setting the value to undefined is not the same.


  delete weakMapInstance[key];

> 3. Why isn't there a way to iterate over the keys?
> I can see that this might be a security issue but iteration is useful
> and security sensitive code can prevent iteration in several ways.


> 4. Why does set throw if the key is not an object but get doesn't?
> Same would go for delete and has if those are added.

More information about the es-discuss mailing list