0

What is the proper name of the following pitfall? I see a lit of people make this mistake, so I'd like to be able to refer to it by name:

for (var i = 0; i < imgs.length; i ++) {
   imgs[i].someFunc = function() {
      // var i not a closure variable
      console.log(imgs[i]);
   };
}
rodrigo-silveira
  • 12,607
  • 11
  • 69
  • 123
  • 2
    “Closure misunderstanding” – Ry- Nov 23 '13 at 06:02
  • I don't know if has a canonical name, but here's the SO question to refer to: http://stackoverflow.com/questions/750486/javascript-closure-inside-loops-simple-practical-example – Barmar Nov 23 '13 at 06:08
  • I'll go with "closure misunderstanding" :-) but I'm afraid there'd be ambiguities involved... Where's Martin Fowler or Doug Crockford when we need them?! – rodrigo-silveira Nov 23 '13 at 06:47

0 Answers0