Any second now I'm going to make a complete fool out of myself, but at worst (and at your cost), I'm learning something. 
Your example is block level scope. Not function level:
```javascript
function foo(i) {
    setTimeout(function() {
        console.log('setinterval on iteration ' + i);
    }, 250);
}

function main() {
  for (var i=0; i < 5; i++) {
    console.log('main on iteration ' + i);
    foo(i);
  }
}
main();
```
gives...

```
main on iteration 0
main on iteration 1
main on iteration 2
main on iteration 3
main on iteration 4
setinterval on iteration 0
setinterval on iteration 1
setinterval on iteration 2
setinterval on iteration 3
setinterval on iteration 4
```

It's because `i` comes in as an argument to the function that scopes it. Isn't that the same for the callback function you have. i.e. `function(k,type) { `