Created
June 22, 2017 13:27
-
-
Save morajabi/c10169d49c78598b33eb8cc4fa5b2596 to your computer and use it in GitHub Desktop.
Cloning objects in javascript with Object.assign({}, src)
This file contains 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
console.group("Cloning objects"); | |
const firstObject = { | |
name: 'Mohammad', | |
}; | |
const clonedObject = Object.assign({}, firstObject); | |
console.log( | |
firstObject, | |
'is cloned like this', | |
clonedObject, | |
`and the result of first === clone is ${firstObject === clonedObject}` | |
); | |
console.groupEnd(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment