Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't MS Edge working with spread element and querySelector?

In another question posted this was there:

var a = {};
a.products = [...document.querySelectorAll('.product')];
console.log(a.products);
<div class="product"> </div>

Edge will fail with the following error:

function expected

However this is working:

    var params = ['hello', '', 7];
    var other = [ 1, 2, ...params];

console.log(params);
console.log(other);

Why isn't the top one working on Edge (it does on Chrome)?

like image 581
Mouser Avatar asked Oct 10 '17 16:10

Mouser


2 Answers

You could use Array.from, which generates an array from an array like object.

this.products = Array.from(document.querySelectorAll('.product'));
like image 117
Nina Scholz Avatar answered Nov 10 '22 23:11

Nina Scholz


Well it looks like Bergi and Felix are on the right track: in this document on MDN they talk about iterators.

Some built-in constructs, such as the spread operator, use the same iteration protocol under the hood:

So where Array does have entries() a nodelist in Edge doesn't and does not support iteration.

Nina's answer is the goto one!

like image 45
Mouser Avatar answered Nov 10 '22 21:11

Mouser