by blurbleblurble · 10y ago · 0 comments
var classNames = [].map.call(nodeList, (entry) => entry.className)
The 'call' function in java script allows you to specify the "this" in the calling of the function. So we grab the map function from an empty array, and call it with nodeList as "this". You can find out more here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...You could also use that to make a super simple method to allow you to call map on any array like object, then you can import this into your other files:
function map(arr, callback) {
return Array.prototype.map.call(arr, callback);
}
Then call it like var classNames = map(nodeList, (node) => node.className); let nodes = Array.from(document.querySelectorAll('.item'));
nodes.forEach(node => console.log(node));
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...