Overriding Map/etc with get/set hooks?
bruant.d at gmail.com
Tue May 21 04:34:15 PDT 2013
Le 21/05/2013 13:19, Brendan Eich a écrit :
> David Bruant wrote:
>> This description ("arbitrary string keys", "bidirectional link with
>> style rule") suggests that you want a proxy (canonical values are in
>> the style rule, the proxy is just a façade with a bit of
>> validation/coercion logic). That's the sort of use case they've been
>> introduced for.
> I don't see why a proxy is required if the API is get/set/has (like
What is the API exactly? This hasn't been clearly described yet.
> We're not making properties appear without knowing their names, so
> this is not a proxy use-case on its face.
Aren't we? That's what I understood when I read (from Tab's initial post):
"When the style rule is mutated to add/remove custom properties, I also
need to mutate the exposed keys on the object."
In any case, making property appear isn't the only use for proxies.
If all property names where known in advance, getter/setters would be
fine for the kind of validation/coercion that's expected here. Since
they aren't known in advance, a proxy seems suitable.
> So Tab: why do you want to abuse Map ...
He wrote in his initial message: "I'd like to convert this over to an ES
Map, as that [...] gets me all the Map extras for free, which is nice."
So I guess: what Map extras do you really want/need? Where would the
object interface (get/set/"in"/delete/for-of) be insufficient?
> ...instead of make a custom class?
Sounds like a good idea too at this point.
More information about the es-discuss