It seems that this references in javascript don't work after a callbackfunction. When running this code:
new Bla().start();
function Bla(){
this.start = function(){
alert("starting");
x(this.done);
}
this.done = function(){
alert("done");
try{
this.postDone();
}
catch(e){
alert(e);
}
}
this.postDone = function(){
alert("postdone");
}
}
function x(callback){
alert("x");
try{
callback();
}
catch(e){
alert(e);
}
}
The alerts will be as follows:
Starting
x
done
TypeError: undefined is not a function
I'd like to know why this problem exists, and preferably a best-practise to solve this.