var socket = io.connect(window.location.hostname); var Game = { nick: "ryz", init: function(){ // Bind events from the server socket.on('event-join', Events.receive.join); socket.on('event-message', Events.receive.message); Chat.init(); } } var Events = { receive: { join: function(data){ console.log("RECEIVE JOIN") for (var i in data.messages) { Chat.add(data.messages[i]); } }, message: function(msg){ console.log("RECEIVE MESSAGE") Chat.add(msg); } }, send: { message: function(msg) { console.log("SE D MMESSAGe") socket.emit('event-message', msg); } }, }; $(Game.init);