Gotcha (programming) - Gotchas in JavaScript Programming Language

Gotchas in JavaScript Programming Language

JavaScript function closures inside loops don’t work intuitively.

var func = ; for(var i = 0; i < 3; i++) { func = function { alert(i); } } func; func;

correct way:

var func = ; for(var i = 0; i < 3; i++) { func = (function(i){ return function{ alert(i); } })(i); //HERE IT IS } func; func;

Read more about this topic:  Gotcha (programming)

Famous quotes containing the words programming and/or language:

    If there is a price to pay for the privilege of spending the early years of child rearing in the driver’s seat, it is our reluctance, our inability, to tolerate being demoted to the backseat. Spurred by our success in programming our children during the preschool years, we may find it difficult to forgo in later states the level of control that once afforded us so much satisfaction.
    Melinda M. Marshall (20th century)

    This is an approach to that universal language which men have sought in vain.
    Henry David Thoreau (1817–1862)