3 ms·
If the prototype extensions were scoped to modules, that would be really nice. ```js // moduleA.js Object.defineProperty(Array, "flatten", ...) export Array
by mlajtos 4y ago
If 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.