views:

475

answers:

2

i'm trying out this jquery plugin http://plugins.jquery.com/project/stylish-select-box/

it works good but with prototype + jquery in noConflict mode this function broke others scripts

Array.prototype.indexOf = function (obj, start) {
     for (var i = (start || 0); i < this.length; i++) {
      if (this[i] == obj) {
       return i;
      }
     }
    };

any help?

+1  A: 

See https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/indexOf

Array already has a native indexOf method. Changing it in ways that don't produce the same results will break things. Heck, even trying to replace a native method may cause problems for methods like hasOwnProperty.

If you really want that function, rename it to myIndexOf or something to avoid the conflict.

Jonathan Fingland
thanks very much!
Davide
no worries. happy to help.
Jonathan Fingland
A: 

Javascript versions prior to 1.6 do not implement indexOf (i.e. IE6). However, you can easily check to see if indexOf is implemented:

if (!Array.prototype.indexOf)
{
    Array.prototype.indexOf = function(obj, start) {
        //
    }
}
Adnan