guest271314 (2019-03-12T20:49:53.000Z)
guest271314 at gmail.com (2019-03-12T21:09:04.530Z)
``` class RequestManager { // verbose `.bind()` __THIS__(method) { return new Proxy(method, { apply: (target, thisArg, argumentsList) => { return method.apply(thisArg, [...argumentsList, { THIS: this }]) } }) } constructor() { this.successMessage = "Xhr successful."; } makeRequest() { var oReq = new XMLHttpRequest(); oReq.addEventListener("load", this.__THIS__(this.responseHandler)); oReq.open("GET", "data:,"); oReq.send(); } responseHandler(e, {THIS} = {}) { console.log(this, e); window.alert(THIS.successMessage) } } var reqManager = new RequestManager(); reqManager.makeRequest(); ``` As a keyword oReq.addEventListener("load", __THIS__ this.responseHandler); // `THIS` within `this.responseHandler` will always refer to `this` instance within this.responseHandler `THIS` will always refer to `this` `class` instance And/or __THIS__ responseHandler(e, {THIS} = {}) { console.log(this, e); if (THIS) // `THIS` will always refer to `this` `class` instance window.alert(THIS.successMessage) }
guest271314 at gmail.com (2019-03-12T21:07:41.542Z)
``` class RequestManager { // verbose `.bind()` __THIS__(method) { return new Proxy(method, { apply: (target, thisArg, argumentsList) => { return method.apply(thisArg, [...argumentsList, { THIS: this }]) } }) } constructor() { this.successMessage = "Xhr successful."; } makeRequest() { var oReq = new XMLHttpRequest(); oReq.addEventListener("load", this.__THIS__(this.responseHandler)); oReq.open("GET", "data:,"); oReq.send(); } responseHandler(e, {THIS} = {}) { console.log(this, e); window.alert(THIS.successMessage) } } var reqManager = new RequestManager(); reqManager.makeRequest(); ``` As a keyword oReq.addEventListener("load", THIS this.responseHandler); // `THIS` within `this.responseHandler` will always refer to `this` instance within this.responseHandler `THIS` will always refer to `this` `class` instance And/or THIS responseHandler(e, {THIS} = {}) { console.log(this, e); if (THIS) // `THIS` will always refer to `this` `class` instance window.alert(THIS.successMessage) }
guest271314 at gmail.com (2019-03-12T21:07:31.503Z)
``` class RequestManager { // vverbose `.bind()` __THIS__(method) { return new Proxy(method, { apply: (target, thisArg, argumentsList) => { return method.apply(thisArg, [...argumentsList, { THIS: this }]) } }) } constructor() { this.successMessage = "Xhr successful."; } makeRequest() { var oReq = new XMLHttpRequest(); oReq.addEventListener("load", this.__THIS__(this.responseHandler)); oReq.open("GET", "data:,"); oReq.send(); } responseHandler(e, {THIS} = {}) { console.log(this, e); window.alert(THIS.successMessage) } } var reqManager = new RequestManager(); reqManager.makeRequest(); ``` As a keyword oReq.addEventListener("load", THIS this.responseHandler); // `THIS` within `this.responseHandler` will always refer to `this` instance within this.responseHandler `THIS` will always refer to `this` `class` instance And/or THIS responseHandler(e, {THIS} = {}) { console.log(this, e); if (THIS) // `THIS` will always refer to `this` `class` instance window.alert(THIS.successMessage) }
guest271314 at gmail.com (2019-03-12T21:03:07.857Z)
``` class RequestManager { __THIS__(method) { return new Proxy(method, { apply: (target, thisArg, argumentsList) => { return method.apply(thisArg, [...argumentsList, { THIS: this }]) } }) } constructor() { this.successMessage = "Xhr successful."; } makeRequest() { var oReq = new XMLHttpRequest(); oReq.addEventListener("load", this.__THIS__(this.responseHandler)); oReq.open("GET", "data:,"); oReq.send(); } responseHandler(e, {THIS} = {}) { console.log(this, e); window.alert(THIS.successMessage) } } var reqManager = new RequestManager(); reqManager.makeRequest(); ``` As a keyword oReq.addEventListener("load", THIS this.responseHandler); // `THIS` within `this.responseHandler` will always refer to `this` instance within this.responseHandler `THIS` will always refer to `this` `class` instance And/or THIS responseHandler(e, {THIS} = {}) { console.log(this, e); if (THIS) // `THIS` will always refer to `this` `class` instance window.alert(THIS.successMessage) }
guest271314 at gmail.com (2019-03-12T20:59:54.676Z)
``` class RequestManager { __THIS__(method) { return new Proxy(method, { apply: (target, thisArg, argumentsList) => { return method.apply(thisArg, [...argumentsList, { THIS: this }]) } }) } constructor() { this.successMessage = "Xhr successful."; } makeRequest() { var oReq = new XMLHttpRequest(); oReq.addEventListener("load", this.__THIS__(this.responseHandler)); oReq.open("GET", "data:,"); oReq.send(); } responseHandler(e, {THIS} = {}) { console.log(this, e); window.alert(THIS.successMessage) } } var reqManager = new RequestManager(); reqManager.makeRequest();```