1

I am trying to clone a quite complicated object with nested sub objects.

The object has a structure like this:

  • Board has n elements of BoardElement
  • BoardElement has n Elements of BoardElementUnits

http://pastebin.com/2NgQQXUC

using jQuery.extend():

var board = $.extend(true, {}, this.game.board)

doesn't clone the nested objects, so I have used JSON to be sure there are no leftover references to the source object.

var boardJSON = JSON.stringify(JSON.decycle(this.game.board));
var board =  JSON.retrocycle($.parseJSON(boardJSON));

This works very well, but the performance is miserable.

1

1 Answer 1

1

Finally found the answer: JQuery doesn't support deep cloning of user defined objects at the moment, but this library does: owl

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.