ES6 - Shallow copy of an object using Object Spread Params (vanilla alternative to _extend())

JS
S
JavaScript

Shallow copy of an object using Object Spread Params (replaces lodash _extend()). Use Cases: merge 2 objects in one, extend one object with another one. Note: Will replace matching properties.

1var app = {
2    title: "My Gaming App",
3    play: () => { console.log('normal play') }
4};
5
6var plugin = {
7    hardcorePlay: () => { console.log('hardcore play') },
8    title: 'My Gaming App Extension Pack'
9};
10var appWithPlugins = { ...app, ...plugin };
11console.log(appWithPlugins);
12
13// Subproperties
14return { 
15    ...state, 
16    loginForm: {
17        ...state.loginForm,
18        email: action.payload.email
19    } 
20}

Created on 6/13/2017