Skip to content

Instantly share code, notes, and snippets.

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 garrettmac/309e9538a5fe0cfc15e0eb25d6888e58 to your computer and use it in GitHub Desktop.
Save garrettmac/309e9538a5fe0cfc15e0eb25d6888e58 to your computer and use it in GitHub Desktop.
ES6 & ES7 Examples
/*
https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015%2Ces2016%2Creact%2Cstage-2&targets=&browsers=&builtIns=false&code=const%20cat%20%3D%20%7B%0A%20%20name%3A%20'Luna'%2C%0A%20%20friends%3A%20%7Bbest%3A%20'Ellie'%7D%2C%0A%20%20legs%3A%204%2C%0A%7D%0Aconst%20strangeCat%20%3D%20%7B...cat%2C%20legs%3A%206%7D%0A%0Aconst%20sameCat%20%3D%20%7B...cat%7D%0Aconsole.log(cat.friends%20%3D%3D%3D%20sameCat.friends)%20%2F%2F%20true%0AsameCat.friends.best%20%3D%20'Buddy'%0Aconsole.log(cat.friends.best)%20%2F%2F%20Buddy%0Aconsole.log(strangeCat)
http://www.reactnativeexpress.com/object_spread
*/
const cat = {
name: 'Luna',
friends: {best: 'Ellie'},
legs: 4,
}
const strangeCat = {...cat, legs: 6}
const sameCat = {...cat}
console.log(cat.friends === sameCat.friends) // true
sameCat.friends.best = 'Buddy'
console.log(cat.friends.best) // Buddy
console.log(strangeCat)
/*
Object {
"friends": Object {
"best": "Buddy"
},
"legs": 6,
"name": "Luna"
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment