Node 5.10 spread operator not working

后端 未结 3 1874
悲哀的现实
悲哀的现实 2021-01-01 11:15

According to the docs, the latest node (Node 5+) should support the spread operator by default, like so:

const newObj = {
        ...oldObj,
        newPrope         


        
3条回答
  •  醉酒成梦
    2021-01-01 12:05

    That's works in Node.js 8.5.0.

    Example:

    var oldObj = {
        oldProperty: 0
    }
    
    var newObj = {
        ...oldObj,
        newProperty: 1
    }
    
    console.log('Old Object: ' + JSON.stringify(oldObj, null, '    '))
    
    console.log('New Object: ' + JSON.stringify(newObj, null, '    '))
    

    Output:

    Old Object: {
        "oldProperty": 0
    }
    New Object: {
        "oldProperty": 0,
        "newProperty": 1
    }
    

    Screenshot from IDE Debug Console:

提交回复
热议问题