Created
June 25, 2018 15:49
-
-
Save chsami/7bf92ecdb018f816f2f5cd95b40c1916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deepCopyExample() { | |
let product = { | |
name: 'beef', | |
price: 10, | |
category: { | |
name: 'food', | |
type: 'meat' | |
} | |
}; | |
let deepCopyOfProduct = JSON.parse(JSON.stringify(product)); | |
console.log('[deepCopy] value before edit: ' + product.name); | |
deepCopyOfProduct.name = 'Ross beef'; | |
console.log('[deepCopy] value after edit: ' + product.name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment