Side navigation
#14134 closed bug (wontfix)
Opened July 15, 2013 02:09PM UTC
Closed July 15, 2013 02:44PM UTC
Last modified July 15, 2013 04:12PM UTC
$.inArray() should be deprecated in favour of $.indexOf()
Reported by: | tisdall@gmail.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.10.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I understand for backwards compatibility we can't just remove the inArray() function, but could we at least deprecate it and make it an alias for $.indexOf() (which would be the original inArray() renamed).
Background
inArray implies that you can do the following:
if ($.inArray("some value", myarray)) { // the value is in the my array }
Where the actual functionality is a cross browser implementation of Array.indexOf() which returns an index.
Attachments (0)
Change History (6)
Changed July 15, 2013 02:44PM UTC by comment:1
resolution: | → wontfix |
---|---|
status: | new → closed |
Changed July 15, 2013 02:57PM UTC by comment:2
Okay, I guess you're not understanding what I'm saying then...
1. Take inArray() and rename in indexOf().
2. create an alias to inArray (ie inArray = indexOf)
3. change documentation to say: we still have inArray for backwards compatibility, but we recommend using indexOf instead since that name actually makes sense.
That way new coders will use indexOf() and make code that actually makes much more sense to read. "deprecate" the name so people will hopefully switch over to the new name but support it indefinitely.
Changed July 15, 2013 03:14PM UTC by comment:3
Great plugin idea.
Changed July 15, 2013 03:39PM UTC by comment:4
rrright.. a "let's make one function have a reasonable name" plugin.
Changed July 15, 2013 03:44PM UTC by comment:5
Sure, you can even have a sarcastic set of docs for it if you want. It's your plugin.
Once oldIE is gone everyone can be using Array#indexOf
anyway, and the args passed to jQuery.inArray
aren't the same so giving it the same name is just asking for a different set of trouble.
Changed July 15, 2013 04:12PM UTC by comment:6
Replying to [comment:5 dmethvin]:
Once oldIE is gone everyone can be usingArray#indexOf
anyway, and the args passed tojQuery.inArray
aren't the same so giving it the same name is just asking for a different set of trouble.
Waiting for browsers to all become compliant would be what you do if you didn't want to use JQuery. One of the biggest reasons for JQuery is cross-browser compatibility.
That's a valid, point, though about the naming confusion... It could be changed to something like .arrayIndexOf() to mitigate that.
My point is that it's a bad name that's been there for years and there's no reason it shouldn't have been fixed in some way that preserves compatibility. [see: http://forum.jquery.com/topic/inarray ]
I agree with you, but considering the amount of extant code that relies on jQuery.inArray this is probably not feasible.