4 ms·
His second bind example is incorrect. function handleClick(i) { this.innerHTML = i; } for (i = 0; i < elems.length; i++) { elems[i].addEvent
by wpears 12y ago
His second bind example is incorrect.
function handleClick(i) {
this.innerHTML = i;
}
for (i = 0; i < elems.length; i++) {
elems[i].addEventListener("click", handleClick.bind(this, i));
}
In the for loop, the this value refers to the global object. To get the desired effect, it should be changed to elems[i] (this piece of code is trying to bind a handler to an element).