question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add NodeList polyfills

See original GitHub issue

At 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:closed
  • Created 6 years ago
  • Reactions:20
  • Comments:21 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
Sora2455commented, Nov 24, 2017

Just to summarise the thread so far:

  1. NodeList is defined as iterable in the DOM Living Standard
  2. Iterable is defined as having a foreach method in the Web IDL Candidate Recomendation
  3. According to MDN, the current versions of Edge, Chrome, Firefox, Opera and Safari all support foreach on Nodelist (at the time of writing).

As this is such an easy thing to polyfill, I say yes, definitely add it.

4reactions
loilocommented, Jan 15, 2019

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:

https://polyfill.io/v3/polyfill.min.js?features=default,NodeList.prototype.forEach

@JakeChampion and others, looks like this issue can be closed now.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found