Because partial is a method placed on the Function prototype, it will be invoked on a function and hence, the function context (the first this) of the method will be that function. We store that in the fn variable for later reference.
The second this is within the anonymous function that we return as the result, and hence it refers to whatever function context is assigned to that function when it is called. We don't know what it is and we don't care. (Remember, the function context is determined by how the function is called, not by how it is declared.) We just make it the function context of the curried function by passing it as the first parameter to apply().
simon tiberius wrote:so, both this refer to different entity?
Yes. Notice that they are within different functions. Each function invocation has it's own function context (this). And the function context (this) is not shared as part of a closure.
Could you please give me an sample code that makes use of this partial function? perhaps I can understand more which "this" refers to what.
Since you posted the code, I assume that you have bought a copy of the MEAP book. Please read that section thoroughly.
Joined: Oct 30, 2012
my guess is ??1 refers to setTimeout, and I really have no idea what ??2 refers to.