javascript - State of a bound parameter in a promise -
i'm curious timing when bind promise.
var = this; function p(){ var promise = new promise( function (yes, no) { /* .... */ /* .... */ }).then(function (val) { /* .... */ /* .... */ }.bind(this)); }.bind(this)
will condition
that ===
allways return true, considering scope outside promise async , .then
might resolved way later in lifecycle.
in other words, this
have same value when first function called, or have value used in .then
part?
the value of this
determined left of dot in calling method. if you're not calling method of object, this
global (window in browser).
in example line var = this
sets value of that global variable window (or global). in specific case, equal that. due side effect, if used different object this
, in
function (yes, no) { /* .... */ /* .... */ }
this !== that
i'm made little fiddle example http://jsfiddle.net/metaf0x9/
Comments
Post a Comment