Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object spread operator throw error in microsoft edge

I have code:

let a = {a: 'a', b: 'b'};
let b = {c: 'c', d: 'd'};
let c = {...a, ...b};

In chrome/firefox/... its display: c = {a: 'a', b: 'b', c: 'c', d: 'd'}, but in microsoft edge it throw error Expected identifier, string or number.

I try to use cdn.polyfill.io and https://babeljs.io/docs/en/babel-polyfill but no luck.

What i can do to run my webpack code in microsoft edge?

like image 825
Vlad Avatar asked Aug 08 '26 09:08

Vlad


1 Answers

It should be available in Edge since 79 without any transcompiler (like Babel) needed (but not IE, don't confuse them).

https://caniuse.com/#feat=mdn-javascript_operators_spread_spread_in_object_literals

That said you could in most situations just use Object.assign() instead if you want -

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

Your code would then be:

let a = {a: 'a', b: 'b'};
let b = {c: 'c', d: 'd'};
let c = Object.assign(a,b)

console.log(c)

Object.assign() is supported since Edge 12:

https://caniuse.com/#feat=mdn-javascript_builtins_object_assign

like image 75
Alex L Avatar answered Aug 10 '26 23:08

Alex L