nodelist-foreach-polyfill
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -7,2 +7,6 @@ ## 1.0.0 | ||
- changed to use [MDN's polyfill](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach) | ||
- changed to use [MDN's polyfill](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill) | ||
## 1.2.0 | ||
- updated to the latest [MDN's polyfill](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill) (thanks [christiansany](https://github.com/christiansany)) |
if (window.NodeList && !NodeList.prototype.forEach) { | ||
NodeList.prototype.forEach = function (callback, argument) { | ||
argument = argument || window; | ||
NodeList.prototype.forEach = function (callback, thisArg) { | ||
thisArg = thisArg || window; | ||
for (var i = 0; i < this.length; i++) { | ||
callback.call(argument, this[i], i, this); | ||
callback.call(thisArg, this[i], i, this); | ||
} | ||
}; | ||
} |
@@ -0,0 +0,0 @@ ISC License |
{ | ||
"name": "nodelist-foreach-polyfill", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Simple polyfill for the NodeList.forEach method.", | ||
@@ -14,2 +14,8 @@ "main": "index.js", | ||
"author": "Jared Williams (imagitama)", | ||
"keywords": [ | ||
"IE11", | ||
"NodeList", | ||
"forEach", | ||
"polyfill" | ||
], | ||
"license": "ISC", | ||
@@ -16,0 +22,0 @@ "bugs": { |
# NodeList.forEach polyfill | ||
MDN polyfill for the `NodeList.forEach` method. | ||
Provides a polyfill for [Nodelist.prototype.forEach()](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach) to all Browsers supporting [ES5](https://caniuse.com/#search=es5). | ||
It polyfills `forEach` support for `NodeList` objects (a common result of `document.querySelectorAll`). | ||
## Native support | ||
Chrome 51, Firefox 50, Opera 38, Safari 10 | ||
Chrome 51, Firefox 50, Opera 38, Safari 10 | ||
Android Browser none, IE Mobile none, IE none | ||
See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach) for more information. | ||
Android Browser none, IE Mobile none, IE none | ||
## Import | ||
See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach) | ||
```JavaScript | ||
// CommonJS | ||
require('nodelist-foreach-polyfill'); | ||
// ES6 Modules import / Typescript import | ||
import 'nodelist-foreach-polyfill'; | ||
``` | ||
## Usage | ||
Import before any usages of `document.querySelectorAll("#foo").forEach((elem) => { ... })` etc. | ||
```JavaScript | ||
// Get Nodelist from DOM via document.querySelectorAll() | ||
var elements = document.querySelectorAll('.foo'); | ||
// Loop through nodelist | ||
elements.forEach(function(element, index, nodelist) { | ||
console.log(this, element, index, nodelist); | ||
}); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3486
32