Design principles for extending ES object abstractions

David Herman dherman at
Sun Jul 10 15:02:14 PDT 2011

>> I'm not sure what Array.prototype methods would or wouldn't work on instances of SubArray.
> All of them.  They are all generic.

We're speaking too broadly here. It depends on what we want to work how. For example, .map can't magically know how to produce a SubArray as its result if that's how SubArray wants it to work. But what I'm actually more concerned about is the behavior of .length. Does the <| semantics make .length work automagically the way it does for ordinary Array instances?

> However, subarray instances have all the internal state and methods that make them true arrays so even if some of the inherited Array methods weren't generic they would still work.

Including .length (which isn't a method, but YKWIM)?


More information about the es-discuss mailing list