let elements = document.querySelectorAll("div"),
callback = (el) => { console.log(el.name); };
elements[Symbol.iterator] = function () {
let i = 0;
const Max = 2;
return {
next () {
if ( i > Max )
return { value : undefined, done: true };
return { value : `\nLe ${elements[i].nodeName} N°${i} \t a pour texte ${elements[i++].textContent}`, done: false};
}
};
};
console.log([...elements]);
JS Bin on jsbin.com