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)

    But as some silly young men returning from France affect a broken English, to be thought perfect in the French language; so his Lordship, I think, to seem a perfect understander of the unintelligible language of the Schoolmen, pretends an ignorance of his mother-tongue. He talks here of command and counsel as if he were no Englishman, nor knew any difference between their significations.
    Thomas Hobbes (1579–1688)