Conversation
Edited 6 months ago

I’m a little confused by.flatMap() in JavaScript. like are people really running .map().flat() so often that they needed to combine them together to save people the trouble of typing three extra characters?

1
0
2

@kasdeya we would assume the rationale is that it can be implemented more efficiently by the browser?

2
0
2

@kasdeya something something, clever way to reduce allocations that will need to be garbage collected later

0
0
2

@tempest ohh - interesting! okay now it makes sense

1
0
2

@kasdeya also just like, broadly speaking, the more steps that can be handled by the browser without going back into JS the better — both in stuff like data transformation and in animation / layout. this is why CSS animations are *basically always* more performant than doing requestAnimationFrame from JS

1
0
2

@tempest interesting omg. I didn’t realize that all of the built-in JavaScript methods and functions were handled by the browser directly - I kind of assumed that they were mostly JS code, kind of like how Python does it. but that makes sense considering that JS has been so aggressively optimized over time

1
0
2