Created
March 3, 2019 15:00
-
-
Save BolajiAyodeji/541edfd41d046662d8e7cd45c0289094 to your computer and use it in GitHub Desktop.
Cloning an Object
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
const circle = { | |
radius: 1, | |
draw() { | |
console.log('draw'); | |
} | |
}; | |
// ONE | |
const another = {}; | |
for (let key in circle) { | |
another[key] = circle[key]; | |
} | |
// TWO | |
const another = Object.assign({}, circle); | |
// THREE | |
const another = {...circle}; | |
console.log(another); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Comment out others when trying out one step to avoid errors!