I am trying to transfer objects from one client to another client, for example. pieces in a multiplayer board game. I have a working solution using JSON.parserand __proto__, but I'm curious to know if there is a better way.
Client sends:
var my_piece = new BoardPiece();
socket.send(JSON.stringify(my_piece));
The server forwards the piece to others:
client.broadcast(piece);
Another client receives:
var your_piece = JSON.parse(json);
your_piece.__proto__ = BoardPiece.prototype;
This is the last step in which I use __proto__, what bothers me, that I can shoot in the leg. Is there a better suggestion?
source
share