Quick actions

cmd+k|ctrl+k

Navigation

Languages

Object.assign side effect

Snippet info

Language

JavaScript

Visibility

public

Author

masonwan

Created

2017-08-25T17:37:34Z

Updated

2017-10-31T20:39:27Z

(() => {
    const x = {
      x: 'x',
    }
    const y = {
      y: 'y'
    }
    console.log(`x:`, x)
    console.log(`y:`, y)
    
    console.log(`Object.assign(x, y):`, Object.assign(x, y))
    
    // Object.assign will manipulate the original object.
    console.log(`x:`, x)
})()

console.log(`========`)

;(() => {
    const x = {
      x: 'x',
    }
    const y = {
      y: 'y'
    }
    // In order to not replace the any object.
    console.log(`Object.assign({}, x, y):`, Object.assign({}, x, y))
    console.log(`x:`, x)
})()
INFO