TIL: Object Spread Operator

Today I learned about the new extend

Posted by Jason Merino on February 12, 2016

The JavaScript spread operator is awesome! Previously when I wanted to merge two objects I would have to pull in underscore or lodash and do something like this.

var obj = _.extend(objectOne, objectTwo, {
	customProp: 'You better believe it!'
})

But now with the help of the wonderful babel compiler (along with the stage-2 preset) I am able to do this for the same effect.

var obj = {
	...objectOne,
	...objectTwo,
	customProp: 'You better believe it!'
}

jason merino

Jason Merino

Jason is a software engineer specializing in JavaScript and web technologies. An avid gardener, aspiring carpenter and a blessed family man.