Skip to content

Commit b8ff621

Browse files
cmcewenfacebook-github-bot-2
authored andcommitted
bind this in onreadystatechange call
Summary: I ran into this problem that `this` is undefined in `onreadystatechange` function calls while using this github api library: https://github.com/michael/github/blob/master/github.js#L72 It seems that in the browser, the `onreadystatechange` function expects `this` to be bound. This example on the xhr spec website can be seen using `this` similarly: https://xhr.spec.whatwg.org/#the-getresponseheader()-method Closes facebook/react-native#5373 Reviewed By: svcscm Differential Revision: D2838940 Pulled By: nicklockwood fb-gh-sync-id: e42184887c7abb0af9c4358a5f33b8c97155624c
1 parent 474b5e9 commit b8ff621

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Libraries/Network/XMLHttpRequestBase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class XMLHttpRequestBase {
247247
if (onreadystatechange) {
248248
// We should send an event to handler, but since we don't process that
249249
// event anywhere, let's leave it empty
250-
onreadystatechange(null);
250+
onreadystatechange.call(this, null);
251251
}
252252
if (newState === this.DONE && !this._aborted) {
253253
this._sendLoad();

0 commit comments

Comments
 (0)