Well, you can keep the for context in your loop, because everything in this case is actually in the same context as the function declared at the beginning.
, , JSLint ( , ).
var my_func, i, list;
for (i = 0; i < list.length; i+= 1) {
my_func = function (i) {
console.log(i);
};
my_func(i);
}
, , , my_func. ! ?
, :
var my_func, i, list;
my_func = function (i) {
console.log(i);
};
for (i = 0; i < list.length; i+= 1) {
my_func(i);
}
. . , JSLint , var , .
: @Flame , jQuery each , , each. , 1.) 2.) jQuery (, index), JSLint ( ) , each (jQuery sauce ).
, $.each(function() {});, .
$( "li" ).each(function( index ) {
alert( index + ": " + $(this).text() );
});
... ...
var fnOutside = function(index) {
alert( index + ": " + $(this).text() );
};
$( "li" ).each(fnOutside);
, , jQuery - , "index" . arguments, , , .
Fiddle-ige
for . . !