Overriding Map/etc with get/set hooks?

Tab Atkins Jr. jackalmage at gmail.com
Wed May 22 09:10:09 PDT 2013


On Wed, May 22, 2013 at 3:44 AM, Brendan Eich <brendan at mozilla.com> wrote:
> Tab Atkins Jr. wrote:
>> If TC39 isn't going to allow us to ever use*any*  of the built-in
>>
>> collection classes just because we have type restrictions we need to
>> enforce, that'll be a pretty raw deal for authors.
>
> Whining about TC39 like this is bad for business. Should I whine about W3C
> to even up the bad karma?

Please, *please*, let's drop the silly turf war rhetoric, it's
embarrassing.  The spec that I'm writing this for happens to be
produced under the W3C aegis, but that's completely irrelevant to my
work.  I named TC39 because *that's the specific group I'm talking to
right now, and which is pushing back*, not because I think it matters
one whit where a spec is produced.

> You can do whatever you want with a subclass or a wrapper. Your o.p. had a
> parenthetical aside about subclass hardships:
>
> (One way to do thistoday  is to subclass Map and provide my own
> get/set/etc. functions, but I need to override a potentially-open set
> (anything that doesn't directly lean on my overridden functions), and
> it doesn't prevent people from directly twiddling my [[MapData]] by
> calling Map.prototype.set.call() on my object.)
>
> ----- end cite -----
>
> But there's no free lunch. Either Map needs hooks lumbering its spec and
> implementations for all users, or you need to do the hooking. Without
> evidence that others need the hooking, as Allen argues, the burden's on you.
> Buy your own lunch.

The evidence for needing hooking is all around.  We need maps and sets
and array *all the time* in DOM and CSSOM and other specs, it's just
that we usually lumber around and invent crappy versions of them
because they didn't exist in JS before.  Look at dataset.  Look at
CSSStyleRule.  Look at my example.  I could just iterate through specs
and find examples all day where we've done something dumb because of
the lack of a good, standardized data structure, but I don't think you
actually need me to do that; you're familiar enough with the mistakes
the web platform has made.

~TJ


More information about the es-discuss mailing list