How to bind an inline anonymous function?

前端 未结 1 1968
旧时难觅i
旧时难觅i 2021-02-07 05:52

I am trying to bind (ie bind(this)) the inline anonymous callback function to the object
How can it be done?

Simplified exampl

1条回答
  •  庸人自扰
    2021-02-07 06:14

    The same way you always use bind.

    Get a reference to the function (such as is returned by a function expression), and call the bind method on it.

    aFunctionWithCallback(this.id, function(data) {
      console.log(this);
    }.bind(this));
    

    0 讨论(0)
提交回复
热议问题