microsoft edge 中的对象传播运算符抛出错误 [英] Object spread operator throw error in microsoft edge
问题描述
我有代码:
let a = {a: 'a', b: 'b'};
let b = {c: 'c', d: 'd'};
let c = {...a, ...b};
在 chrome/firefox/... 中显示:c = {a: 'a', b: 'b', c: 'c', d: 'd'}
,但在 microsoft edge 中它会抛出错误 Expected identifier, string or number
.
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
.
我尝试使用 cdn.polyfill.io
和 https://babeljs.io/docs/en/babel-polyfill
但没有成功.
I try to use cdn.polyfill.io
and https://babeljs.io/docs/en/babel-polyfill
but no luck.
如何在 microsoft edge 中运行我的 webpack 代码?
What i can do to run my webpack code in microsoft edge?
推荐答案
{ ...obj }
语法称为Object Rest/Spread Properties",它是 ECMAScript 2018 的一部分,Edge Legacy 不支持.您可以使用 Babel 进行转译它.
The { ...obj }
syntax is called "Object Rest/Spread Properties" and it's a part of ECMAScript 2018 which is not supported by Edge Legacy. You can use Babel to transpile it.
如果只想在非 Node.js 环境中使用,可以使用 babel-standalone.您只需要在脚本中加载 babel-standalone 并在脚本标签中编写要转译的脚本,类型为 text/babel" 或 text/jsx",Edge Legacy 中的结果将是 {"a":"a","b":"b","c":"c","d":"d"}
:
If you just want to use it in non Node.js environments, you can use babel-standalone. You just need to load the babel-standalone in your script and write the script you want to transpile in script tag with type "text/babel" or "text/jsx", the result in Edge Legacy will be {"a":"a","b":"b","c":"c","d":"d"}
:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.18.1/babel.min.js"></script>
</head>
<body>
<script type="text/babel">
let a = { a: 'a', b: 'b' };
let b = { c: 'c', d: 'd' };
let c = { ...a, ...b };
console.log(JSON.stringify(c));
</script>
</body>
</html>
这篇关于microsoft edge 中的对象传播运算符抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!