这个问题已经在这里有一个答案:
- 如何访问正确的`this`回调里面? 10个回答
在应用程序:
var bootstrap = new Bootstrap();
bootstrap.init( this, this.onBootstrapComplete );
在引导:
this.init = function( app, completeHandler ){
_app = app;
_completeHandler = completeHandler;
...
}
...
var _allReady = function(){
_completeHandler( _app );
}
早在应用程序:
this.onBootstrapComplete = function( app )
{
app.something();
app.someValue = ...
}
我想进去onBootstrapComplete 此背景下。 它的工作原理,但它看起来不正确的:)
如果让我们说,我想直接从应用程序调用onBootstrapComplete,我将不得不调用它.onBootstrapComplete( 本 )。
我如何能做到这一点,所以我的onBootstrapComplete看起来是这样的:
this.onBootstrapComplete = function()
{
this.something();
this.someValue = ...
}