Possible Duplicate:
setTimeout() inside JavaScript Class using “this”
I found this interesting article on how to implement custom events in javascript with prototype: http://www.nczonline.net/blog/2010/03/09/custom-events-in-javascript/
But I'm a little stuck on how to implement this, I have this simple app with a interval that triggers a function every second.
function App() {
window.test = 'test';
this.loginTimer = setInterval(this.checkLogin, 1000);
EventTarget.call(this);
}
App.prototype = new EventTarget();
App.prototype.constructor = App;
App.prototype.checkLogin = function() {
this.fire('test');
}
But this is throwing me an error:
Uncaught TypeError: Object [object Window] has no method 'fire'
I've used the same method as described in the article, is there something i'm missing?