Skip to content

Instantly share code, notes, and snippets.

@bennycode
Created December 2, 2019 13:45
Show Gist options
  • Select an option

  • Save bennycode/d02b03cdbeb731e99b5ec4693dfb104d to your computer and use it in GitHub Desktop.

Select an option

Save bennycode/d02b03cdbeb731e99b5ec4693dfb104d to your computer and use it in GitHub Desktop.
Stateful copies
const test = {
tree: {
branch1: 10,
branch2: 20,
}
};
const copies = {};
for (let i = 0; i < 10; i++) {
test.tree.branch1 += 1;
test.tree.branch2 += 1;
copies[i] = JSON.parse(JSON.stringify(test));
}
console.log('First state change', copies[0].tree.branch1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment