Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

javascript and spread operator as unexpected token

I have strange problem with spread operator. When I use this code in chrome console, it works great:

var obj1 = { food: 'pizza', car: 'ford' }
var obj2 = { animal: 'dog' }

const merged = { 
  ...obj1,
  ...obj2
};

...but when I use it in my project in VSC, I'm getting an error

enter image description here

unexpected token is indicated in ...obj1

Does someone know how to fix that?

question from:https://stackoverflow.com/questions/65875841/javascript-and-spread-operator-as-unexpected-token

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the same issue. My babel.config.js had Chrome 58 as a target. According to this browser support table on MDN, spread in object literals are only supported in Chrome 60 and onwards.

To fix this, you either need to increase your minimum supported browser version, or change your code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...