LearnBoost/socket.io — Issue #711: Array.prototype.indexOf on page kills socket.io client
Author: crickeys
Created: 2012-01-06 04:01:03+00:00
State: open

I have a customer who uses our code which makes use of socket.io. I isolated a bug that would seem to just never set the event emitters of the socket.io-client so I would get Object # has no method 'on' when setting an event listener on the socket.

I isolated some javascript on their website and ran some tests. If I include this code after I load my sockets javascript file then it breaks. Without that code it's all good. I'm not sure if this would be classified as a bug in socket.io or simply a bad use of overriding the indexOf for Arrays. Or maybe I'm missing something else?

I can't just tell the client to take the code out because we have lots of clients and they can't/won't always control that. Is there a way to make socket.io more robust to avoid this issue? Any ideas?

Here is the offending code:

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