Node 5.10 spread operator not working

后端 未结 3 1878
悲哀的现实
悲哀的现实 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:02

    What you tried to use is called object spread and is not part of the es2015 specification. Node only supports the regular spread in function calls and array literals. Unfortunately not even array destructuring is supported yet, although they link to the MDN page which describes both structuring and destructuring use of ....

    You can use Object.assign instead:

    const newObj = Object.assign({}, oldObj, {
      newProperty: 1
    });
    

提交回复
热议问题