Skip to content

Instantly share code, notes, and snippets.

@jakelacey2012
Created October 22, 2016 21:17
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 jakelacey2012/083e1131354606e0d1bbd302e9b2ec13 to your computer and use it in GitHub Desktop.
Save jakelacey2012/083e1131354606e0d1bbd302e9b2ec13 to your computer and use it in GitHub Desktop.
/**
* 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