Skip to content

Instantly share code, notes, and snippets.

@rtoal
Created December 14, 2016 16:52
Show Gist options
  • Save rtoal/5d7e3fb3946486c0bd31d23f2bb7b4b8 to your computer and use it in GitHub Desktop.
Save rtoal/5d7e3fb3946486c0bd31d23f2bb7b4b8 to your computer and use it in GitHub Desktop.
Polyfill allowing iteration of Safari's HTMLCollection objects
// Polyfill because Safari's HTMLCollections are not iterable
if (typeof HTMLCollection.prototype[Symbol.iterator] !== 'function') {
HTMLCollection.prototype[Symbol.iterator] = function () {
let i = 0;
return {
next: () => ({done: i >= this.length, value: this.item(i++)})
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment