var self = this?

后端 未结 8 1375
失恋的感觉
失恋的感觉 2020-11-22 09:10

Using instance methods as callbacks for event handlers changes the scope of this from \"My instance\" to \"Whatever just called the callback\"

相关标签:
8条回答
  • 2020-11-22 09:46

    Just adding to this that in ES6 because of arrow functions you shouldn't need to do this because they capture the this value.

    0 讨论(0)
  • 2020-11-22 09:50

    I think it actually depends on what are you going to do inside your doSomething function. If you are going to access MyObject properties using this keyword then you have to use that. But I think that the following code fragment will also work if you are not doing any special things using object(MyObject) properties.

    function doSomething(){
      .........
    }
    
    $("#foobar").ready('click', function(){
    
    });
    
    0 讨论(0)
提交回复
热议问题