服务器端:
//When a player connects, all the players will get this message.
game.sockets.emit('entrance',
{
id: socket.id,
players: [],
message: 'Player ' + socket.id + ' is online',
store: function(id, object){
this.players.push({id: id, object: object});
}
});
客户端:
socket.on('entrance', function(data){
console.log(data.message);
data.store(data.id, new Car('hero').init());
});
这给了我以下错误:
它console.log
是存储在对象中的消息,没有问题,所以看起来像是函数内部某处的错误。
谢谢!