Skip to content

Instantly share code, notes, and snippets.

@joelnet
Created March 1, 2019 07:29
Show Gist options
  • Select an option

  • Save joelnet/1abc665c56bf94fcf7152642844a9ac9 to your computer and use it in GitHub Desktop.

Select an option

Save joelnet/1abc665c56bf94fcf7152642844a9ac9 to your computer and use it in GitHub Desktop.

Revisions

  1. joelnet created this gist Mar 1, 2019.
    23 changes: 23 additions & 0 deletions rest-spread-tricks-07.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    const user2 = {
    id: 200,
    name: 'Vince Noir'
    }

    const user4 = {
    id: 400,
    name: 'Bollo',
    quotes: ["I've got a bad feeling about this..."]
    }

    const setDefaults = ({ quotes = [], ...object}) =>
    ({ ...object, quotes })

    setDefaults(user2)
    //=> { id: 200, name: 'Vince Noir', quotes: [] }

    setDefaults(user4)
    //=> {
    //=> id: 400,
    //=> name: 'Bollo',
    //=> quotes: ["I've got a bad feeling about this..."]
    //=> }