Re: David’s ProxyMap

David Bruant bruant.d at gmail.com
Sat Oct 20 11:20:17 PDT 2012


2012/10/20 Axel Rauschmayer <axel at rauschma.de>

> 1. Accidentally accessing inherited properties: fixed
>> 2. Can’t safely invoke methods, because those might be overridden: still
>> a problem (right?)
>> 3. __proto__: fixed
>>
> [...]
> About your second point, it assumes that we want all objects to have
> Object.prototype methods. I'm not so sure it should be a goal.
>
>
> It’s loosely related to Allen’s object model reformation [1]: you’d want
> the [] “operator” to get and set collection elements, but would still want
> to be able to invoke map-related methods. Currently, the two are mutually
> exclusive.
>
I see what you mean. In my case, I have completely ditched method
invocation. I have replaced it with syntactic sugar for some methods, but
it may not be applicable for all Map.prototype methods.


> 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.


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?


> Now, there are reasons against this and I’m mainly wondering if actually
> using the new API has changed your or Tom’s mind.
>
Since in the object model reformation proposal, @elementGet & friends are
symbols (unique I would assume since there is no need for them to be
private), I think there is not a single line to change to the proxy
proposal as it is now to make it work properly with the object model
reformation proposal. If that's the case, it means that assuming the object
model reformation passes, it'll be possible for proxies to separate
property access from method invocation.
Can Allen, Tom or Mark (or anyone familiar enough with both proposals)
confirm?

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121020/4808bc83/attachment.html>


More information about the es-discuss mailing list