> Another idea: one could use the `in` operator to check whether a key exists
> in the map (only for ProxyMap at the moment, possibly for all collections in
> the future).
> This is not possible, because maps are objects and have own properties too.
> In Firefox Nightly:
>
> var m = new Map();
> m.azerty = 123; // own property of m, not a map internal key/value pair
> console.log(m.azerty, m.get('azerty')) // 123, undefined
>
> I find this snippet and the result consistent with my expectations.
I was thinking about ProxyMap. And my bad – it’s already there (the `has`
method of the handler). So you can do:
var pm = new ProxyMap();
pm["key"] = "value";
console.log("key" in pm); // true
console.log("toString" in pm); // false
> Currently, proxies make no distinction between a property read access and a
> method invocation. In my experience, it would be nice if that distinction
> would be there – if only that one didn’t have to curry for method invocations
> which must be a performance issue and is a fairly common use case (remotely
> invoking web services etc.).
> I'm not following. Can you provide an example, please?
For remote method invocation and for things like a “method missing” handler,
you have to use the following pattern:
let handler = {
get(target, name, receiver) {
return (...args) => {
// send name and args over the wire
}
}
};
If methods were separate from property read accesses, no currying would be
necessary here, e.g.:
let handler = {
callMethod(target, name, receiver, args) {
// send name and args over the wire
}
};
For ProxyMap, you could allow getting and setting elements in addition to the
invocation of map methods. That’s only possibly if the distinction is made.
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss