Add NodeList polyfills
See original GitHub issueAt the guardian we realized yesterday, that there is currently no polyfill for NodeList.forEach()
. According to MDN there is no support for the feature in the following browsers:
Browser | Version |
---|---|
Chrome | < 51 |
Firefox | <50 |
IE | * |
Opera | <38 |
Safari | <10 |
The possible polyfill would be quite small:
if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = function (callback, argument) {
argument = argument || window;
for (var i = 0; i < this.length; i++) {
callback.call(argument, this[i], i, this);
}
};
}
Do you think it’s worth adding this as a single polyfill, or would you rather like to polyfill all potential missing methods on NodeList
, which are .entries(), forEach(), item(), keys(), values()
?
I’m happy to work on a PR for this.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:20
- Comments:21 (3 by maintainers)
Top Results From Across the Web
nodelist-foreach-polyfill - npm
Simple polyfill for the NodeList.forEach method.. Latest version: 1.2.0, last published: 5 years ago. Start using nodelist-foreach-polyfill ...
Read more >Add NodeList.forEach polyfill to support IE11 - Drupal
The media library uses the .forEach method on a NodeList element. This is not supported in IE11 and we need a polyfill to...
Read more >nodelist-foreach-polyfill | Yarn - Package Manager
Provides a polyfill for Nodelist.prototype.forEach() to all Browsers supporting ES5. Native support. Chrome 51, Firefox 50, Opera 38, Safari 10. Android Browser ...
Read more >NodeList.prototype.forEach() - Web APIs | MDN
The forEach() method of the NodeList interface calls the callback given in parameter once for each value pair in the list, in insertion ......
Read more >forEach polyfill for NodeLists - YouTube
Until recently, the forEach method was only available for Arrays.Over the last 18 months it has been added by the different browsers for ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just to summarise the thread so far:
As this is such an easy thing to polyfill, I say yes, definitely add it.
For anyone subscribed to this: This feature is available in polyfill.io v3 which has been out for a couple days.
It’s not in the default feature set though, you have to include it manually:
@JakeChampion and others, looks like this issue can be closed now.