var self = this?

后端 未结 8 1573
失恋的感觉
失恋的感觉 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: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(){
    
    });
    

提交回复
热议问题