5 ms·
"New Array methods have been implemented: Array.prototype.keys" Dafuq. Yes I'm aware how Arrays are just objects in JS but please stop bastardizing the Array
by rubiquity 13y ago
"New Array methods have been implemented: Array.prototype.keys"
Dafuq.
Yes I'm aware how Arrays are just objects in JS but please stop bastardizing the Array data type even further. This is also part of ES6 so I don't blame Mozilla for implementing it.
- gkoberger 13y agoWhat do you mean by bastardizing? I'm not sure when I'd ever use Array.keys, but it seems like it could be potentially useful -- and more importantly, totally in the spirit of JavaScript.
- cheald 13y agoIt seems like a poorly-chosen name. I like the idea of being able to get an indexes iterator, but I'd probably have named it `indexes()` rather than `keys()`, as the latter tends to be much more strongly associated with dictionaries.
- kybernetikos 13y agoArrays in javascript are not what you might think. They are defined by the spec to be maps where certain keys (those that are string representations of Uint32 numbers) are treated differently, and a magic property length which is always one more than the largest such key. They are not necessarily dense - there can be gaps, and any kind of relationship to a contiguous block of memory is purely at the discretion of the implementation. I presume that your complaint is really about calling such a thing an array, because a 'keys' method is certainly not a further bastardization of what was already in the spec.
- Benvie 13y agoAll iterable objects (Arrays, Strings, TypedArrays, Maps, and Sets) come with the same set of iterator-creating methods (keys, values, entries).
- mnemonik 13y agoThis is the most important point; it is totally consistent.