From my personal experience, in addition to using anonymous functions to induce a region, I also used it for for-loops to close. This can be useful when the DOM element needs to store its account and you do not have access to libraries like jQuery etc.
, 100 DIV . DIV 1, 56- div, 56.
, , -
for (var i = 0; i < 100; ++i) {
myElements[i].onclick = function() {
alert( 'You clicked on: ' + i );
};
}
99, 99. i .
, ,
for (var i = 0; i < 100; ++i) {
(function(count){
myElements[count].onclick = function() {
alert( 'You clicked on: ' + count );
};
})(i);
}
i .