// https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/
// https://toddmotto.com/ditch-the-array-foreach-call-nodelist-hack/
// https://developer.mozilla.org/en-US/docs/Web/API/NodeList
// Bad solutons:
[].forEach.call(document.querySelectorAll('a'), function(x) { x.style.color = "red"; });
[].map.call(document.querySelectorAll('a'), function(x) { return x.href; });
// also bad:
NodeList.prototype.forEach = Array.prototype.forEach;
NodeList.prototype.map = Array.prototype.map;
// However it's convenient in a browser's developper tool.
// proper ways:
function forEach(f,a){
for (var i = 0; i < a.length; i++) f(a[i]);
}
forEach(function(x) { x.style.color = "red"; }, document.querySelectorAll('a'));
function map(f,a){
var r=[];
for (var i = 0; i < a.length; i++) r.push(f(a[i]));
return r;
}
map(function(x) { return x.href; }, document.querySelectorAll('a'));