Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object doesn't support property or method 'jscomp_symbol_iterator0'

I'm using babel 6.7 to build a single page React.js web app. I've tried to include all the relevant polyfills e.g. babel-polyfill to make it compatible with ES5 browsers. Even still, I get a javascript error every now and again like this

Object doesn't support property or method 'jscomp_symbol_iterator0'

mostly from users on windows 7 & 8.1 running IE10+.

I'm assuming it's something to do with js Symbol.iterator not being supported. Is there a way I can polyfill this for older browsers?

Thanks!

like image 969
Peter Matev Avatar asked Oct 19 '22 10:10

Peter Matev


1 Answers

In my case the error:

Object doesn't support property or method 'Symbol.iterator'

Pointed to a specific line related to the ES6 syntax of a for loop. I.e., I had this:

for(let el of document.getElementsByClassName('especial-els')) { /* ... */ }

And all I needed to do to fix it was changing this loop to an "old-style" loop:

let especialEls = document.getElementsByClassName('especial-els');
for(let i = specialEls.length - 1; i >= 0; i--) { /* ... */ }

This error only occurred in the Edge browser (not in Chrome and not in Firefox) and particularly only in this for(let i of iterator) loop (I have other loops of this kind iterating over arrays and the error does not show up). My guess is that document.getElementsByClassName() returns a "especial" iterator.

like image 146
Armfoot Avatar answered Oct 27 '22 21:10

Armfoot