Yesterday, I asked this question: Passing a method for later evaluation and thought that it was as simple as passing a prototype method, rather than calling it immediately after access, resets this
to Window
. However, today I came across this code today:
sSharing.shareFileWithGroup( node, groupId, d.resolve, d.reject ); //d is a Angular promise
and when shareFileWithGroup calls its 3rd or 4th argument in its body, it correctly calls any functions previously passed to d.then
, i.e. the passed method can locate the original object it was accessed from. What exactly are the rules for setting this
when calling a prototype method? The two situations seem to be inconsistent.
EDIT: My understanding is that the passed method d.resolve/reject
should not be able to call then functions previously passed as arguments to .then
, but it does. My question is how it does it? The only thing I can think of is if promises are built into JS or the methods aren't actually using the prototype and are being put in the constructed object directly.