JSFiddle - React, Tailwind, and code Playground
JavaScript
"use strict";
class Example {
constructor () {
this.checkAuth();
}
checkAuth () {
document.write("Checking auth now. ");
var iid = setInterval(() => {
if (true) { // Have to do some dumb check here
clearInterval(iid);
this.authenticate(this.handleAuthResult)
}
}, 500);
}
authenticate (callback) {
callback({value: true});
}
handleAuthResult (result) {
document.write(`The result is ${result.value}. `);
this.setResult(result, this.loadThePage)
// ^ `this` is undefined here. How can I ever set the result?
}
// Another asynchronous thing
setResult (result, callback) {
callback();
}
loadThePage() {
document.write("The code never gets here, but the page should load now. ");
}
};
var example = new Example();