You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe it would be useful to mention callback binding, I know that personally was confusing for me in the beginning. For instance, you might expect this to work:
But actually it will not work since the innermost callback is called from the context of someOtherObj, and this doesn't resolve to the Something instance (so this.value end up being something else).
The solutions are foo(function () { this.value... }.bind(this)), var self = this; foo(function () { self.value... }), or maybe ES6 arrow functions (since they take their context from wherever they were created), () => { this.value... }.
The text was updated successfully, but these errors were encountered:
Maybe it would be useful to mention callback binding, I know that personally was confusing for me in the beginning. For instance, you might expect this to work:
But actually it will not work since the innermost callback is called from the context of
someOtherObj
, andthis
doesn't resolve to theSomething
instance (sothis.value
end up being something else).The solutions are
foo(function () { this.value... }.bind(this))
,var self = this; foo(function () { self.value... })
, or maybe ES6 arrow functions (since they take their context from wherever they were created),() => { this.value... }
.The text was updated successfully, but these errors were encountered: