Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14134 closed bug (wontfix)

$.inArray() should be deprecated in favour of $.indexOf()

Reported by: tisdall@… 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.

Change History (6)

comment:1 Changed 6 years ago by Rick Waldron

Resolution: wontfix
Status: newclosed

I agree with you, but considering the amount of extant code that relies on jQuery.inArray this is probably not feasible.

comment:2 Changed 6 years ago by tisdall@…

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.

comment:3 Changed 6 years ago by dmethvin

Great plugin idea.

comment:4 Changed 6 years ago by tisdall@…

rrright.. a "let's make one function have a reasonable name" plugin.

comment:5 Changed 6 years ago by dmethvin

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.

comment:6 in reply to:  5 Changed 6 years ago by tisdall@…

Replying to dmethvin:

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.

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 ]

Note: See TracTickets for help on using tickets.