Hey.
Consider an example.
var heights = []; // переменная, которая будет хранить высоты элементов $("div").each(function(indx, element){ heights.push($(element).height()); }); // в итоге, в переменную heights будут помещены значения высот всех div-элементов It should be noted that the this variable, inside the callback function, will store the same value as the second domElement parameter that is passed to it. Thus, the previous example could look like this:
var heights = []; // переменная, которая будет хранить высоты элементов $("div").each(function(indx){ heights.push($(this).height()); }); // в итоге, в переменную heights будут помещены значения высот всех div-элементов The question is - WHY the this variable, inside the callback function, will store the same value as the second domElement parameter that is passed to it?
this refers to the object in which the function lies. I do not understand WHERE this anonymous function lies (in which object it is nested). If I deal with a regular function, then I know WHERE I declared it (within which object), respectively, I know where the this property will refer to when it goes to work out the local function code.
callback.call( obj[ i ], i, obj[ i ] )andcallback.call( obj[ i ], i, obj[ i ] )- Grundycallfunction - Grundy