title: Deep copy in ES6 using the spread syntax
body: <p>I am trying to create a deep copy map method for my Redux project that will work with objects rather than arrays. I read that in Redux each state should not change anything in the previous states.</p>
  <pre class="lang-js prettyprint-override"><code>export const mapCopy = (object, callback) =&gt; {
      return Object.keys(object).reduce(function (output, key) {
  
          output[key] = callback.call(this, {...object[key]});
  
          return output;
        },
     {});
  }
  </code></pre>
  <p>It works:</p>
  <pre class="lang-js prettyprint-override"><code>return mapCopy(state, e =&gt; {
  
      if (e.id === action.id) {
           e.title = 'new item';
      }
  
      return e;
  })
  </code></pre>
  <p>However it does not deep copy inner items so I need to tweak it to:</p>
  <pre><code>export const mapCopy = (object, callback) =&gt; {
      return Object.keys(object).reduce(function (output, key) {
       
      let newObject = {...object[key]};
      newObject.style = {...newObject.style};
      newObject.data = {...newObject.data};
  
      output[key] = callback.call(this, newObject);
  
      return output;
      }, {});
  }
  </code></pre>
  <p>This is less elegant as it requires to know which objects are passed.
  Is there a way in ES6 to use the spread syntax to deep copy an object?</p>