Skip to content

Instantly share code, notes, and snippets.

@BolajiAyodeji
Created March 3, 2019 15:00
Show Gist options
  • Save BolajiAyodeji/541edfd41d046662d8e7cd45c0289094 to your computer and use it in GitHub Desktop.
Save BolajiAyodeji/541edfd41d046662d8e7cd45c0289094 to your computer and use it in GitHub Desktop.
Cloning an Object
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);
@BolajiAyodeji
Copy link
Author

Comment out others when trying out one step to avoid errors!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment