News for hackers. Stuff that matters.
Re:Real-World JavaScript Anti-Patterns by wpears on Tuesday December 30, 2014 @01:15PM (#8815797)
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).

There are no comments on this comment yet.