title: How to pass a "new" object in JavaScript in Socket.IO
body: <p>I'm trying to pass objects from one client to another client, e.g. pieces in a multiplayer board game. I have a working solution using <code>JSON.parser</code> and <code>__proto__</code>, but I'm curious to know if there is a better way.</p>
  
  <p>Client sends:</p>
  
  <pre><code>var my_piece = new BoardPiece();
  // ... my_piece is assigned data, like x-y coordinates
  socket.send(JSON.stringify(my_piece));
  </code></pre>
  
  <p>Server forwards the piece to others:</p>
  
  <pre><code>client.broadcast(piece);
  </code></pre>
  
  <p>Another client receives:</p>
  
  <pre><code>var your_piece = JSON.parse(json);
  your_piece.__proto__ = BoardPiece.prototype; // provide access to BoardPiece's functions
  </code></pre>
  
  <p>It's the last step where I use <code>__proto__</code> that I'm concerned I may be shooting myself in the foot. Is there a better suggestion?</p>