Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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
You can’t perform that action at this time.