From b8ff6212f84efebcf3ba2de3e1999d3e68e0c574 Mon Sep 17 00:00:00 2001 From: Connor McEwen Date: Mon, 18 Jan 2016 08:54:14 -0800 Subject: [PATCH] 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 https://github.com/facebook/react-native/pull/5373 Reviewed By: svcscm Differential Revision: D2838940 Pulled By: nicklockwood fb-gh-sync-id: e42184887c7abb0af9c4358a5f33b8c97155624c --- Libraries/Network/XMLHttpRequestBase.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Network/XMLHttpRequestBase.js b/Libraries/Network/XMLHttpRequestBase.js index 1fffb713f971c8..29073b7d1ca24d 100644 --- a/Libraries/Network/XMLHttpRequestBase.js +++ b/Libraries/Network/XMLHttpRequestBase.js @@ -247,7 +247,7 @@ class XMLHttpRequestBase { if (onreadystatechange) { // We should send an event to handler, but since we don't process that // event anywhere, let's leave it empty - onreadystatechange(null); + onreadystatechange.call(this, null); } if (newState === this.DONE && !this._aborted) { this._sendLoad();