Search code examples
prototypejsjquery

Jquery + Prototype in noConflict() mode, Array.prototype.indexOf broken


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?


Solution

  • 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.