I have a board class:
var board = new Board();
I want to clone a board and run a function movePieceon a new board:
var newBoard = board;
newBoard.movePiece('4a', '3b');
Because I just appoint him, both boardand newBoardwill have displaced part.
How can I clone boards to create an exact copy called newBoard, on which I can move the piece, and the original board remains the same?
I tried several different methods, for example:
Object.assign({}, orig)
and
function clone(orig) {
let origProto = Object.getPrototypeOf(orig);
return Object.assign(Object.create(origProto), orig);
}
from http://www.2ality.com/2014/12/es6-oop.html
source
share