jQuery.map:jQuery.uniqueSort: Accept array-like input, fix typos#1214
Conversation
Apart from array-like inputs being officially allowed in `jQuery.uniqueSort` now, in a few places in examples it used to be referred to as `unique` instead of `uniqueSort`.
| <argument name="array" type="Array"> | ||
| <desc>The Array to translate.</desc> | ||
| <argument name="array" type="ArrayLikeObject"> | ||
| <desc>The Array or an Array-like object to translate.</desc> |
There was a problem hiding this comment.
Are we sure this is true for all versions back to 1.0?
There was a problem hiding this comment.
@timmywil I've just checked. In versions 1.0, 1.1, 1.2, 1.3, 1.4 & 1.5 jQuery.map is written using a for loop that would work with array-likes as well. Moreover, jQuery 1.2 implemented jQuery.fn.map which uses jQuery.map on jQuery objects which are not arrays.
jQuery 1.6 added support for iterating on objects in jQuery.map so it had to detect "arrays" separately. The 1.6 detection code is a bit cryptic:
// jquery objects are treated as arrays
isArray = elems instanceof jQuery || length !== undefined && typeof length === "number" && ( ( length > 0 && elems[ 0 ] && elems[ length -1 ] ) || length === 0 || jQuery.isArray( elems ) )but it does detect array-likes. 1.9 extracted that logic and uses:
isArray = isArraylike( elems ),so even the util name has "array-like" in the name.
I think we can assume that array-likes have been supported since 1.0 even if that was not the original intent.
There was a problem hiding this comment.
Thanks for looking at so many versions
Co-authored-by: Timmy Willison <4timmywil@gmail.com>
1.
jQuery.map: Accept array-like input2.
jQuery.uniqueSort: Accept array-like input, fix typosApart from array-like inputs being officially allowed in
jQuery.uniqueSortnow, in a few places in examplesit used to be referred to as
uniqueinstead ofuniqueSort.The second one is particularly interesting. For some reason, there's even an example directly claiming
jQuery.uniqueSortdoesn't work on array-likes when its code says something completely opposite - especially that it's sometimes used on jQuery collections. We even test it on an "Arrayish" class!