

A Classic JavaScript Interview Question - chcokr
https://medium.com/@chcokr/a-beginners-thoughts-on-programming-languages-part-4-1-solutions-for-js-callbacks-in-loops-799840754d62

======
eastbayjake
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);
        };
      }

