David’s ProxyMap

David Bruant bruant.d at gmail.com
Thu Oct 25 04:11:36 PDT 2012

Le 25/10/2012 12:42, Axel Rauschmayer a écrit :
>> I'm not sure I understand the benefit of making it easy to develop
>> APIs where foo.bar() is not roughly equivalent to (x =
>> foo.bar).apply(foo). Am I misunderstanding something?
> Right. Keeping that invariant is important.
> I’d like to avoid (the cognitive and performance cost of) having to
> curry whenever you implement methods via a proxy (which seems the most
> important use case for proxies).
> Being able to distinguish between a property read access and a method
> invocation (which, spec-internally, you can do via a reference) is
> indeed rarely interesting. It could be used for ProxyMap, but that
> seems iffy, design-wise:
> let pm = new ProxyMap();
> pm.size = 123; // create a map entry
> pm.size(); // invoke the size() method
I've thought about .size and .keys, .values, etc.
The sugar I added doesn't support these (well, .keys can be sugared with
the keys/enumerate traps :-p). Everything may be doable with ProxyMap
static methods.
I have not given myself the goal to emulate all Map/WeakMap
capabilities. But when one just wants a key->value store with object
syntax (get, set, delete, 'in'), ProxyMap does the job.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121025/4d7daa54/attachment.html>

More information about the es-discuss mailing list