1 comment

[ 2.6 ms ] story [ 11.5 ms ] thread
I like your IIFE there. It's more elegant than the way I usually see this one fixed:

  for (var i = 0; i < domElems.length; ++i) {
    domElems[i].onclick = clickHandler(i);
  }

  function clickHandler(n){
    return function(){
      console.log(n);
    };
  }