I m confused at a point in javascript object concept. I have replicated my issue in a simple object and was wordering that why it is not working. Please have a look at the code.
var app = {
initialize : function(){
this.bindEvents();
},
bindEvents : function(){
console.log('bindEvents check');
window.addEventListener('load', this.onWindowLoad, false);
},
onWindowLoad : function(){
console.log('window is done loading');
this.someFunction();
},
someFunction : function(){
console.log('coming from some Function');
}
}
app.initialize();
this.someFunction();
doesn’t work in ‘onWindowLoad’ function however 'app.someFunction()'
works. this.bindEvents();
works in ‘initialize ‘ function, so this works in the first function but not in the last one.
WHY 'this'
isn’t working onWindowLoad function ? Thanks.
http://jsbin.com/xeziw/3/edit