I have written some namespaced javascript and I'm having trouble binding to window events (such as scroll, resize) and retaining access to my instance of the app, for example:
var app = new function() {
this.init = function() {
var self = this;
window.onresize = self.resize;
};
this.resize = function() {
var self = this;
console.log(self); // Gives me the window!
};
};
app.init();
I'd rather not have to declare the function then and there with window.onresize = function()...
, because I want to be able to call my app.resize()
function independently too. Is there a better way to do this within the scope of my app?