I am trying following and expecting setTimeout to be executed every second for different index. I am able to achieve it thru bind method as commented, however when I use IIFE for the same, it is giving expected output but without any delay. Can anyone suggest correct implementation for the same.
function count(){
for(i=0;i<5;i++){
//var f = console.log.bind(null, i); //WORKING AS EXPECTED
var f = ((index)=>{
console.log(index);
})(i);
setTimeout(f, 1000*i);
}
}
count();
//OUTPUT (Without any delay)
0
1
2
3
4