Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Problem with simple javascript object.

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #163929
    sayedtaqui
    Participant

    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

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.