为什么 MS Edge 不使用 spread element 和 querySelector?
Why isn't MS Edge working with spread element and querySelector?
在发布的另一个问题中:
var a = {};
a.products = [...document.querySelectorAll('.product')];
console.log(a.products);
<div class="product"> </div>
Edge 将失败并出现以下错误:
function expected
然而这是可行的:
var params = ['hello', '', 7];
var other = [ 1, 2, ...params];
console.log(params);
console.log(other);
为什么最上面的那个不能在 Edge 上运行(它在 Chrome 上运行)?
您可以使用 Array.from
,它从类似于对象的数组生成数组。
this.products = Array.from(document.querySelectorAll('.product'));
看来 Bergi 和 Felix 的方向是对的:在 MDN 上的 document 中,他们讨论了迭代器。
Some built-in constructs, such as the spread operator, use the same iteration protocol under the hood:
因此,Array 确实有 entries()
,但 Edge 中的 nodelist
没有也不支持迭代。
Nina 的回答是转到第一个!
更新到 2020 年,Edge 现在在内部使用 Chrome v8。
要求用户下载最新版本的 Edge。无需在旧版 Edge 中处理这种特定情况。
在发布的另一个问题中:
var a = {};
a.products = [...document.querySelectorAll('.product')];
console.log(a.products);
<div class="product"> </div>
Edge 将失败并出现以下错误:
function expected
然而这是可行的:
var params = ['hello', '', 7];
var other = [ 1, 2, ...params];
console.log(params);
console.log(other);
为什么最上面的那个不能在 Edge 上运行(它在 Chrome 上运行)?
您可以使用 Array.from
,它从类似于对象的数组生成数组。
this.products = Array.from(document.querySelectorAll('.product'));
看来 Bergi 和 Felix 的方向是对的:在 MDN 上的 document 中,他们讨论了迭代器。
Some built-in constructs, such as the spread operator, use the same iteration protocol under the hood:
因此,Array 确实有 entries()
,但 Edge 中的 nodelist
没有也不支持迭代。
Nina 的回答是转到第一个!
更新到 2020 年,Edge 现在在内部使用 Chrome v8。 要求用户下载最新版本的 Edge。无需在旧版 Edge 中处理这种特定情况。