semmypurewal/LearningWebAppDev

Creating function inside closure

Closed this issue · 1 comments

via Gilbert Desport:

I have a question regarding the JavaScript For loop example in Chapter 4 "Interactivity" (page 136). I couldn't get this to work as expected - it highlights the last(3rd) tab regardless of the tab clicked. Would I be correct in thinking this may be because the variable used when building the function (tabnumber) will always be set to 3 at runtime (and accessed via JavaScript closure) i.e. it will reference the last iterated value?