Created
October 22, 2016 21:17
-
-
Save jakelacey2012/083e1131354606e0d1bbd302e9b2ec13 to your computer and use it in GitHub Desktop.
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
/** | |
* Object copying with no mutation. | |
*/ | |
console.log('Test ObjectASssign'); | |
const x = { | |
name: 'Will', | |
age: 35, | |
hair: { | |
color: 'brown', | |
length: 'long', | |
curly: true, | |
}, | |
fat: false, | |
fastestMile: '6m', | |
}; | |
console.log('x is ', x) | |
const mu = { | |
name: 'Another Name', | |
age: 20, | |
hair: { | |
color: 'brown', | |
length: 'long', | |
anotherAttribute: { | |
another: 'This is a thing', | |
another: 'This is another thing', | |
}, | |
curly: true, | |
}, | |
fat: false, | |
fastestMile: '6m', | |
}; | |
const y = Object.assign({}, x, mu); | |
console.log('y is ', y); | |
console.log('----- next test -----') | |
var a = {name:'will', things:[1, 2, 3]}; | |
var b = Object.assign({}, a, {name: "Fred"}); | |
console.log(a, b); | |
b.things = [1, 2, 3, 4]; | |
console.log(a, b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment