kutyel / linq.ts

🌀LINQ for TypeScript

Home Page:http://kutyel.github.io/linq.ts/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why not extend the plain JavaScript 'Array' type ?

JaggerJo opened this issue · comments

Is there a reason why these methods are not availiable on any plain JavaScript Array ?
We could simply add them to the Prototype, right ?

For Example

Array.prototype.firstOrDefault = (...) => x

and

interface Array<T> {
    firstOrDefault(...) : T;
}

Actually its a very interesting question! Thanks for asking! The answer is mainly that extending prototypes in JavaScript its a very bad practice. It's only allowed to add missing standard features (pollyfils) that are not yet implemented. Generally its a much better pattern to wrap an abstraction and use that instead, which is exactly what the List component is, a wrapper of an internal JS array 😉

BTW: you can support the library by sharing it and giving it a ⭐️ in GitHub! 😉