tc39 / proposal-flatMap

proposal for flatten and flatMap on arrays
https://tc39.github.io/proposal-flatMap
214 stars 19 forks source link

IsArray *and* arguments exotic objects? #39

Closed ljharb closed 6 years ago

ljharb commented 6 years ago

Typically, Array methods are liberal in what they accept, although they always return arrays.

These methods clearly can't take concat-spreadables because NodeLists, and can't take arraylikes because Strings, however, applying array methods to arguments via .call is a common pattern.

If https://github.com/tc39/proposal-flatMap/blob/master/proposal.html#L55 changed to "If spreadable is true or element is an arguments exotic object", then it should work.

(linking to #37 as well)

bakkot commented 6 years ago

applying array methods to arguments via .call is a common pattern

I think that will still work with no changes, right? The difference would only arise if you had arguments inside of another array (or arguments object) which you're calling .flatten or .flatMap on.

ljharb commented 6 years ago

ahhh yes you're right, this issue would only be about if i had [arguments].flatten(); Array.prototype.flatten.call(arguments) would work fine.

Thanks for clarifying :-)