Use bound this and this of function scope in a function bound with bind()

后端 未结 2 1315
再見小時候
再見小時候 2021-01-26 04:50

I have the following function call:

$(\".selector\").on(\"click\", callback.bind(this, param1, param2));

Inside my callback function I would li

2条回答
  •  不思量自难忘°
    2021-01-26 04:55

    when this in your callback belongs to the scope of callback bind not the scope of the event.

    this might work but I am not sure i understand what you are trying to do

    $(".selector").on("click", function(event){
        callback.bind(event.type, param1, param2)
    });
    

    this points to the dom element your event occured while the event already has the type which you want to pass to the 2nd bind (2nd because in theory your .on() is a bind as well)

提交回复
热议问题