Re: [heycam/webidl] Figure-out what supporting Array-subclassing implies (#345)

> But the point is, we have a tool for getting the observable behavior being described. If that's the behavior we want, and we have a tool for it, why not just use the tool?

Two reasons.

1. I keep getting told that it's a legacy feature that no one should use.

2. "It's not an Array because of some relatively arcane details that are barely even *known* among authors, let alone used" casually ignores all the *other* stuff that Arrays do that authors actually *do* use, and want to use on Array-like things.  It's *silly* that we have to do `[].slice(document.querySelector(...)).map(...)`, just because the platform, as it currently stands, doesn't define `map` (and the slew of other Array methods) on Array-likes.

All I want is something that satisfies the following:

1. Lets you iterate over it.
2. Lets you use the various Array methods on it (map, foreach, filter, etc.) with reasonable (typesafe) semantics
3. Stretch goal: lets you do `obj[1] = foo` on it with typechecking.

> Now whether this is what web authors want, I can't tell you. AWB would claim that they want the "typecheck as late as possible" behavior, and that this is faster because you only do the typechecks when you really care about them and not at every API boundary, and further that any typechecks should be duck-typing, not branding. There are obviously philosophical differences about that...

Given that this is contrary to the entire philosophy of WebIDL, I don't think AWB's opinion is particularly germane here.  (Plus, his old proposal for a `[]` hook is precisely what would *allow* you to early-typecheck.)  I refuse to entertain arguments that Array-likes are special snowflakes here that should behave differently from every other interface on the platform.

---

If the only way I can do all of this is to make this a Maplike with a k-v iterator that only uses integers for keys (imposing some semantics on what integers you can use), and manually define a mixin that duplicates the Array builtins, then by golly I'll do it.  I'll be very unhappy about it, and I'm certain that y'all will be too, but I'm not going to define an API with a broken, slow, or needlessly-weak interface just because no one is willing to actually define something useful.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/issues/345#issuecomment-297794825

Received on Thursday, 27 April 2017 18:11:42 UTC