I'm trying to write some JS object. Getting stuck on something, I don't understand how contexts work. Here is a simple example :
var MyApp = function(el) {
this.el = el;
};
MyApp.prototype.bind = function() {
window.setTimeout(this.start, 300);
}
MyApp.prototype.test = function(msg) {
console.log(msg);
}
MyApp.prototype.start = function() {
console.log(this); // Returns the window context
this.test('Hello'); // Doesn't work, of course.
}
var myapp = new MyApp(el);
myapp.bind();
Problem is when calling the start method, I'm in the window context because of the window.setTimeout. Is there a way to fix this or is it a pattern design issue?
Thanks ;)