[removed] Creating a persistently bound function

后端 未结 1 1608
迷失自我
迷失自我 2021-01-23 10:50

I realise a question like this is asked pretty frequently (I\'ve probably read every one of them over the past few days trying to understand how to fix this) - but in this case,

相关标签:
1条回答
  • 2021-01-23 11:42

    You simple wrap the call to aFoo.sendData in an anonymous function:

    aBar.getSomething(data, function () {
        aFoo.sendData();
    });
    

    Because your referencing aFoo.sendData, the reference to this inside sendData is no longer aFoo. When using the anonymous function, you're not referencing the function; you're simply invoking it as a method on the aFoo instance, so this is still aFoo.

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