I have a Object that calls some async functions, using a prototype chain:
function Wow() {
this.myAsyncFunction();
}
Wow.prototype.myAsyncFunction = function() {
// Once my async function is complete, I fire a callback
this.completed(); // Does not work
}
I would like to use it like this:
var wow = new Wow();
wow.completed = function() {
alert('Awesome');
}
Here is a code snippet I created to simulate a my idea.
function Wow() {
this.ok = document.getElementById('ok');
this.wait();
}
Wow.prototype.wait = function() {
this.ok.innerHTML = "Waiting..."
window.setTimeout(function() {
this.completed();
}, 1000);
}
var wow = new Wow();
wow.completed = function() {
wow.ok.innerHTML = "Compelted";
};
#ok {
font-size: 28px;
color: red;
}
<div id="ok"></div>
I spent more than a hour searching google and StackOverflow for a solution, but I'm finding difficulties to even search for it.