Skip to content

Instantly share code, notes, and snippets.

@bob-lee
Created November 24, 2017 18:41
Show Gist options
  • Select an option

  • Save bob-lee/e7520bfcdac266e5490f40c2759cc955 to your computer and use it in GitHub Desktop.

Select an option

Save bob-lee/e7520bfcdac266e5490f40c2759cc955 to your computer and use it in GitHub Desktop.
Polyfill for IE11 missing NodeList.forEach
if ('NodeList' in window && !NodeList.prototype.forEach) {
console.info('polyfill for IE11');
NodeList.prototype.forEach = function (callback, thisArg) {
thisArg = thisArg || window;
for (var i = 0; i < this.length; i++) {
callback.call(thisArg, this[i], i, this);
}
};
}
@Abdull

Abdull commented Nov 15, 2019

Copy link
Copy Markdown
//Polyfill for HTMLCollection.forEach
if ('HTMLCollection' in window && !HTMLCollection.prototype.forEach) {
  console.info('polyfill HTMLCollection for IE11');
  HTMLCollection.prototype.forEach = function (callback, thisArg) {
    thisArg = thisArg || window;
    for (var i = 0; i < this.length; i++) {
      callback.call(thisArg, this[i], i, this);
    }
  };
}

@rornfdlek

Copy link
Copy Markdown

You saved me!! Thank you so much!!!!!

@LianSheng197

Copy link
Copy Markdown

Thanks!! It's very simple and work!

@dimitristahos

Copy link
Copy Markdown

🍺🍺🍺🍺🀘🀘🀘🀘

@ivan-markin

Copy link
Copy Markdown

πŸ™πŸ™πŸ™

@Gaarmy

Gaarmy commented May 20, 2020

Copy link
Copy Markdown

Thank you so much!

@PaliyStepan

Copy link
Copy Markdown

thanks dude! u saved me )

@kflogdev

Copy link
Copy Markdown

After searching high and low, this finally worked (specifically for Sharepoint SPFx)! Thank you!

@oxyyyyy

oxyyyyy commented Dec 23, 2020

Copy link
Copy Markdown

Thanks
Anybody knows why Babel ignores .forEach() ?

@darkcris1

Copy link
Copy Markdown

Babel

Thanks
Anybody knows why Babel ignores .forEach() ?

Because babel doesn't care of polyfills. It only focus on transpiling your code

@oxyyyyy

oxyyyyy commented Feb 16, 2021

Copy link
Copy Markdown

Babel

Thanks
Anybody knows why Babel ignores .forEach() ?

Because babel doesn't care of polyfills. It only focus on transpiling your code

Oh, for sure..
thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment