it does not work in every browser. the purpose of jQuery and similar
libraries is to streamline development and create a (mostly)
consistent foundation to build on, regardless of browser. if you're
interested in gaining some performance, or just using the latest JS
features, i'd suggest implementing this yourself. IMO, it doesn't
belong in the core, but it would be easy to add.

something like this:
if (Array.prototype.indexOf) {
    $.inArray = function(elem, array) {
        return array.indexOf(elem);
}

because $.inArray is already a part of the core, you'd just be
replacing it where the native indexOf method exists on Arrays.
otherwise, you'd just be using the standard implementation. hope that
helps.

On Aug 24, 12:28 pm, "Cesar Sanz" <the.email.tr...@gmail.com> wrote:
> Does it works for every browser?
>
> ----- Original Message -----
> From: "gurdiga" <gurd...@gmail.com>
> To: "jQuery (English)" <jquery-en@googlegroups.com>
> Sent: Sunday, August 23, 2009 1:07 PM
> Subject: [jQuery] $.inArray optimisation
>
> > Hello,
>
> > The $.inArray function is defined in
> >http://jqueryjs.googlecode.com/svn/trunk/jquery/src/core.js
> > as:
>
> > inArray: function( elem, array ) {
> > for ( var i = 0, length = array.length; i < length; i++ ) {
> > if ( array[ i ] === elem ) {
> > return i;
> > }
> > }
>
> > return -1;
> > },
>
> > I'm wondering: would it be possible to take advantage of the built-in
> > indexOf method of the Array present in FF Javascript engines? Im
> > thinking of something like:
>
> >    if (typeof Array.prototype.indexOf === 'function') {
> >        return array.indexOf(elem);
> >    }
>
> > What do you think?

Reply via email to