Skip to content

Instantly share code, notes, and snippets.

@vicapow
Created January 20, 2013 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vicapow/4581353 to your computer and use it in GitHub Desktop.
Save vicapow/4581353 to your computer and use it in GitHub Desktop.
var sockets = [...] ; // some array of sockets
for(var i = 0; i < sockets.length; i++){
socket.on( 'CardPick', function(data) {
Draft.cardPick( data, draftId, socket );
// `socket` will always be the last item in `sockets` every time the callback is called on any of the sockets
});
}
for(var i = 0; i < sockets.length; i++){
(function(socket){
socket.on( 'CardPick', function(data) {
Draft.cardPick( data, draftId, socket );
// `socket` will now be what we expect it to be.
});
})(socket);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment