New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add [Symbol.iterator]() methods to NodeList, TouchList, etc. #545
Comments
NodeList.prototype[Symbol.iterator] = [][Symbol.iterator] |
@zloirock I tried the code you posted and it works, but I don't know why. What does Another question: There is/was a "browser-polyfill.js" file. Would it be okay to add this code there so that everyone can use iterators with DOM lists out of the box? |
After thinking about it I realized that |
It's not the responsibility of 6to5 to polyfill this behaviour. This is better suited for core-js which is what 6to5 uses. |
@sebmck I guess that makes sense. 6to5 is just repackaging existing polyfills. I'll create an issue with core-js and see what they say. |
@zloirock I didn't realize you were the maintainer of core-js. Is this polyfill something you'd be interested in as a optional include with core-js or should I start a separate project for stuff like this? |
It accesses the iterator method of an array. Maybe this is easer to understand: var arr = [];
NodeList.prototype[Symbol.iterator] = arr[Symbol.iterator];
// or
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]; I assume (didn't look at the code), just like other array methods, this method is agnostic and works on values that are array-like. |
@KevinB7 As I wrote above, |
Just my two cents: I also assumed these would be provided by core-js. If you do decide to have them, please also include them in Nodish polyfill behind |
Show me spec, I can't find it. |
I found something in the whatwg DOM spec that mentions NodeLists having "iterable" as part of their interface in the IDL: https://dom.spec.whatwg.org/#nodelist. |
Just to expand on the
|
Ok, I will add |
Avaliable in 0.4.6. |
Thanks! |
I test it in IE8, this seems not work for me.
And I transformed it use babeljs/repl The result is below
But this didn't work in IE8. You can test it using the code below
I found out of the problem is
|
I was reading this MDN page on for...of: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/for...of and they mentioned that you could use it with stuff from the DOM like NodeList. I tried it and it didn't work so I ended up polyfilling it with this code:
It actually works and lets do stuff like:
I'd like to create a pull request for this and the other DOM lists. Where's a good place to put browser only polyfills?
The text was updated successfully, but these errors were encountered: