2 ms·
NodeList.prototype.filter = Array.prototype.filter; and you can querySelectorAll('...').filter(el => ...) without any copies. ditto for other mentioned functi
by megous 4y ago
NodeList.prototype.filter = Array.prototype.filter;
and you can querySelectorAll('...').filter(el => ...) without any copies.
ditto for other mentioned functions. Prototypal nature of Javascript is there for a reason.
- shirogane86x 4y agoIn every single project or company I've ever worked on/with, monkey patching was _extremely_ frowned upon (for good reasons). Also, how would you be able to filter without any copies? you'd at least be forced to make one. filter is _not_ supposed to mutate anything. so you'd have to create a new Array and/or NodeList, and put the filtered values back in. Even then, doing all this stuff for what is effectively one single copy that is likely to be insignificant at a performance level is, in my opinion, excessive. I just copy once and make the code clearer.