[jQuery] Weird exception when extending Array

[jQuery] Weird exception when extending Array


Hi all
I've a strange issue that bugs me...
Everything works fine in a page we've got, but when I add this simple
function
to one of our js files
Array.prototype.contains = function (value){
var i;
for (i=0; i < this.length; i++) {
if (this[i] === value) {
return true;
}
}
return false;
}
and reload the page I get this exception:
elem.className has no properties
http://localhost:8080/atalaya-web/js/jquery-1.2.1.js
Line 617
This is because this function
remove: function( elem, c ){
elem.className = c != undefined ?
jQuery.grep( elem.className.split(/\s+/), function(cur){
return !jQuery.className.has( c, cur );
}).join(" ") : "";
}
is invoked with a window.document object, that has no class associated. Thus
elem.className fails
It's really weird, because without the above prototype function everything
works fine...
For the moment I've just rewritten it like array_contains(array,value) and
issue solved, but I'd like
to know what's causing this.
Does anybody have a clue?
thanks a lot, cheers
Francesco
--
View this message in context: http://www.nabble.com/Weird-exception-when-extending-Array-tp14362261s27240p14362261.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.