Skip to content

Instantly share code, notes, and snippets.

@rafaelmaeuer
Last active August 24, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelmaeuer/77a883bfbb14f1c27044644ad8cf48f7 to your computer and use it in GitHub Desktop.
Save rafaelmaeuer/77a883bfbb14f1c27044644ad8cf48f7 to your computer and use it in GitHub Desktop.
// Shallow Copy (with reference)
var objectIsNew = objectIsOld;
// Name will change in both objects
objectIsNew.name = 'NameChanged';
// Deep Copy e.g. with JSON functions
var objectIsNew = JSON.parse(JSON.stringify(objectIsOld));
// Name will only change in new object
objectIsNew.name = 'NameChanged';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment