I have a JavaScript variable that stores a websocket connection like so:
var ws = $.websocketSettings.factory(url);
$(ws)
.bind('open', $.websocketSettings.open)
.bind('close', $.websocketSettings.close)
.bind('message', $.websocketSettings.message)
.bind('error', $.websocketSettings.error)
.bind('relaySent', $.websocketSettings.relayTimeout)
.bind('relayRetry', $.websocketSettings.relayRetry)
.bind('jumpStart', $.websocketSettings.jumpFactory);
However in case the connection drops, I have a jumpStart event that resets the ws variable with a new connection.
jumpFactory: function(event){
var ws = this;
ws = $.websocketSettings.factory( getEngineUrl() );
return ws;
},
Will this break the bound events on ws? I’m seeing some strange behaviour so trying to pinpoint the cause.
You don’t bind your events to any variable, but to its value – object referenced in it. Assigning new object to variable won’t somehow automagically transfer those bindings from old object to new. Additionally those events will continue to fire as long as this object old object is referenced from somewhere.