Event callback scope #91

Closed
alebsack opened this Issue Sep 9, 2011 · 2 comments

3 participants

@alebsack

I noticed on Firefox 6 (possibly other browsers) that the scope of event callbacks is inconsistent with Webkit's Websocket implementation. Websocket in Webkit will call event callbacks within the scope of the Websocket object. In Firefox 6, it is in the scope of the Window.

Here's a patch that addresses the issue, and it works for me:

diff --git a/web_socket.js b/web_socket.js
index 947a637..d62e0b6 100644
--- a/web_socket.js
+++ b/web_socket.js
@@ -149,7 +149,7 @@
eventsi;
}
var handler = this["on" + event.type];

  • if (handler) handler(event);
  • if (handler) handler.apply(this, [event]);
    };

    /**

@kanaka

This would probably be a good thing to file as a bug with Mozilla too (if you haven't already). They may just not have thought about it and it would be good to get things consistent everywhere (and being called with this set to the WebSocket object makes the most sense).

@gimite
Owner

Thanks for the report and patch. Pulled at:
66f79da

@kanaka I confirmed that MozWebSocket in Firefox 6 does correct scope handling. I guess @alebsack only mentioned about Firefox 6 + web-socket-js.

@gimite gimite closed this Sep 10, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment