From 51746b6bdd5239fef4667b6f8ff4413fd60597f2 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 4 Jun 2015 22:43:00 +0100 Subject: js: pay attention to the scope of the variables use the keyword var to avoid assigning them to the global object window. Signed-off-by: Olivier Gayot --- cao-common.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'cao-common.js') diff --git a/cao-common.js b/cao-common.js index 5c40f86..145173c 100644 --- a/cao-common.js +++ b/cao-common.js @@ -34,7 +34,7 @@ var CAO = function() { }; ws.onmessage = function(evt) { - message = JSON.parse(evt.data); + var message = JSON.parse(evt.data); if (message['type'] == 'notification') { handle_notification(message['content']); @@ -56,7 +56,7 @@ var CAO = function() { }; var handle_response = function(response) { - rq = request_queue.shift(); + var rq = request_queue.shift(); if (response['status'] != 0) { alert(response['info']); @@ -75,9 +75,9 @@ var CAO = function() { case 'view_player_cards': if (response['status'] == 0) { $('#white_cards').show(); - for (i in response['result']) { - idx = response['result'][i][0]; - desc = response['result'][i][1]; + for (var i in response['result']) { + var idx = response['result'][i][0]; + var desc = response['result'][i][1]; white_cards[idx] = desc; @@ -116,8 +116,8 @@ var CAO = function() { /* XXX intentional fallback */ case 'view_played_cards': if (response['status'] == 0) { - for (i in response['result']) { - desc = response['result'][i]; + for (var i in response['result']) { + var desc = response['result'][i]; played_cards.push(desc); self.on_show_played_card(i, desc); @@ -138,7 +138,7 @@ var CAO = function() { this.gen_callback_white_card = function(index) { return function() { - request = { + var request = { 'op': 'play_white_card', 'card_id': index, }; @@ -150,7 +150,7 @@ var CAO = function() { this.gen_callback_played_card = function(index) { return function() { - request = { + var request = { 'op': 'designate_card', 'card_id': index, }; @@ -161,9 +161,9 @@ var CAO = function() { }; $('#btn_join').click(function() { - game_name = prompt('Name of the game'); + var game_name = prompt('Name of the game'); - request = { + var request = { 'op': 'join_game', 'game_name': game_name, }; @@ -172,7 +172,7 @@ var CAO = function() { }); $('#btn_pick_black').click(function() { - request = { + var request = { 'op': 'pick_black_card', }; request_queue.push('pick_black_card'); @@ -180,7 +180,7 @@ var CAO = function() { }); $('#btn_collect').click(function() { - request = { + var request = { 'op': 'collect_cards', }; request_queue.push('collect_cards'); @@ -188,7 +188,7 @@ var CAO = function() { }); this.request_show_cards = function() { - request = { + var request = { 'op': 'view_player_cards', }; @@ -197,7 +197,7 @@ var CAO = function() { ws.send(JSON.stringify(request)); }; this.request_show_black_card = function() { - request = { + var request = { 'op': 'view_black_card', }; @@ -205,7 +205,7 @@ var CAO = function() { ws.send(JSON.stringify(request)); }; this.request_show_played_cards = function() { - request = { + var request = { 'op': 'view_played_cards', }; -- cgit v1.2.3