Or a single line change:

inArray: function( elem, array ) {
    if(array.indexOf) return array.indexOf(elem);
    for ( var i = 0, length = array.length; i < length; i++ ) {
         if ( array[ i ] === elem ) {
            return i;
        }
    }
    return -1;
 },

The availability of indexOf is tested every time but I don't think it
makes much difference.

On Sep 3, 7:24 pm, Andrea Giammarchi <andrea.giammar...@gmail.com>
wrote:
> Since probably somebody left the Dynamic post where it is, I would like to
> open this new discussion about jQuery.inArray, which is basically an indexOf
> and which is not optimized.
>
> I simply quote myself to make things clear, Regards.
>
> ----------------------------------------------------------------------------------
>
> Just a curiosity, are you using indexOf with jQuery instances as well?
>
> In this case line 411 of core.js
>
>     inArray: Array.prototype.indexOf ?
>         (function( indexOf ) {
>             return function( elem, array ) {
>                 return indexOf.call( array, elem );
>             }
>         })( Array.prototype.indexOf ) :
>         function( elem, array ) {
>             for ( var i = 0, length = array.length; i < length; i++ ) {
>                 if ( array[ i ] === elem ) {
>                     return i;
>                 }
>             }
>
>             return -1;
>         }
>     ,
>
> otherwise if this function supposes to work only with array (due to explicit
> name) just this:
>
>     inArray: Array.prototype.indexOf ?
>         function( elem, array ) {
>             return array.indexOf( elem );
>         } :
>         function( elem, array ) {
>             for ( var i = 0, length = array.length; i < length; i++ ) {
>                 if ( array[ i ] === elem ) {
>                     return i;
>                 }
>             }
>             return -1;
>         }
>     ,
>
> I am sure they'll follow this logic so I would not worry about trunk.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to