7 ms·
I wish they would've gone with Array.flatten() instead of Array.prototype.flat. We have `Array.from` and `Array.of` in the language already why not continue tha
by pg_bot 8y ago
I wish they would've gone with Array.flatten() instead of Array.prototype.flat. We have `Array.from` and `Array.of` in the language already why not continue that trend? Am I missing some reason why that couldn't have happened? Also strange to see that infinite flattening is not the default behavior.
- __david__ 8y agoThe entire article is about why that couldn't happen.
- lovich 8y agoWhy isn't versioning being put into the spec now? If we have array.prototype.flatten why can't we have array.prototype.v1.flatten so that we have an easy out to this in the future? Apis do this all the time, why can't JavaScript of backwards compatibility is this important?
- bsimpson 8y agoThe static methods take probably-not-arrays and return arrays. An instance method takes an existing array (`this`) and returns a modified array. Of course, you could implement a static flatten, but it goes against the grain of all the other instance methods (map, reduce, filter, etc.). Considering how often they are chained together, it would be especially weird.
- pg_bot 8y agoIf the pipeline operator gets accepted into JS[0], I think we should go in the direction of copying those as static methods. An example would look like: [1,2,[3,4,5]] |> Array.flatten() |> Array.filter((x) => x % 2 === 0) |> Array.map((x) => x * 2) |> Array.reduce((acc, x) => acc + x) [0]: https://github.com/tc39/proposal-pipeline-operator https://github.com/tc39/proposal-pipeline-operator