Created
March 19, 2018 04:55
-
-
Save shelldandy/da437ea6a134dca26a4ceec42b88e893 to your computer and use it in GitHub Desktop.
Make a document.querySelectorAll loopable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Make a document.querySelectorAll loopable | |
* @author Todd Motto | |
* @tutorial https://toddmotto.com/ditch-the-array-foreach-call-nodelist-hack | |
* @param {NodeList} elements | |
* @param {Function} callback function that takes element and index | |
* @param {this} scope what this refers to | |
*/ | |
const loopQuery = (elements, callback, scope) => { | |
for (let i = 0; i < elements.length; i++) { | |
callback.call(scope, elements[i], i) | |
} | |
} | |
export default loopQuery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment