5 ms·
I will welcome ".include(a)" into my code in place of the awkward ".indexOf(a)!== -1". Better late than never, I guess.
by nkg 9y ago
I will welcome ".include(a)" into my code in place of the awkward ".indexOf(a)!== -1".
Better late than never, I guess.
- tomatsu 9y agoToo bad it was renamed. "Contains" was a much better name. "Contains" is used everywhere else - the DOM API included (Element.classList.contains).
- deleted 9y ago[deleted]
- runarberg 9y agoIf I remember correctly, the array methods `.includes`, `.every`, and `.some` were renamed because of collision with prototype.js's `.contains`, `.all`, and `.any` respectively.
- haukur 9y agoIt's very unfortunate that the APIs of libraries that extend JavaScript builtins affect the development of the language to this degree.
- eximius 9y agoThat is the stupidest thing I've ever heard. Why would that matter? That would encourage me the naming choice was in the right direction!
- thaiphanvevo 9y agoLots of websites still use Prototype.js. Magento still has it as a dependency. Don't want to break the web!
- eximius 9y agoWould it break the web though? Wouldn't they just override the native implementation with a JS one?
- curtisblaine 9y agoThen the two implementations would probably be incompatible (different signatures, different implementation / return values) and would cause unexpected errors down the chain. So, essentially, breaking the web and making it difficult to fix it.
- curtisblaine 9y agoWould it be bad though? A lot of APIs change in the browser space. WebRTC was broken a hundred times. Libraries depending on Prototype would probably be old, maybe insecure. You need to break it from time to time, you can't be backwards compatible all the time.
- devmunchies 9y ago`.includes()` is used in lodash so lots of JavaScript developers are already used to that anyway.
- Macha 9y agoLodash switched to using includes when it became clear the standard was going to use includes. See e.g. Lodash 2 docs which had contains as the standard name, and `include` as the alias: https://lodash.com/docs/2.4.2#contains https://lodash.com/docs/2.4.2#contains
- combatentropy 9y agoA little less awkward: ~array.indexOf(a) https://www.joezimjs.com/javascript/great-mystery-of-the-tilde/ https://www.joezimjs.com/javascript/great-mystery-of-the-til...
- nawitus 9y agoI think that's worse because it's more difficult to understand.