4 ms·
The problem with prototypical inheritance is that people will use it. And now you can’t add anything ever again without this risk. I absolutely love the abilit
by Waterluvian 4y ago
The problem with prototypical inheritance is that people will use it. And now you can’t add anything ever again without this risk.
I absolutely love the ability to monkey patch in upcoming features. But I avoid adding my own array functions. Unfortunate, IMO, because it’s a really neat trick.
- mlajtos 4y agoIf the prototype extensions were scoped to modules, that would be really nice. ```js // moduleA.js Object.defineProperty(Array, "flatten", ...) export Array // moduleB.js import { Array } from "moduleA" console.log([[1],[2]].flatten()) ```
- cprecioso 4y agoYou can kind of do that by creating your own subclass, right?
- mlajtos 4y agoWell, you can subclass it, but you would have to convert regular array to your subtype every type you would want to use some extra property. With proposed way, you can still enjoy the terseness of the language.