我有以下代码:
import $ from 'jquery';
import _ from 'underscore';
import $script from 'scriptjs';
var _apiLoaded = $.Deferred();
window.initApi = function () {
_apiLoaded.resolve();
delete window.initApi;
};
class X {
init(){
url = "blahblah"
$script([url + '&callback=initApi'], function () {
});
_apiLoaded.done(function () { <Execution is skipping this function>
test.initialized = true;
});
}
getPred(query, callbackSuccess, callbackError) {
// this.init();
_apiLoaded.done(function () { <Execution is skipping this function>
blah blah...
});
};
this.getPred(query);
});
}}
我是从模型做的: gc = new X(); gcd = gc.init();
gc.getPred(requestParams.predQ,_。bind(this.success,this),errorHandler);
你能在上面的代码和解释中解释吗?为什么它不执行_apiLoaded.done(function(){... 主要在getPred中 在_apiLoaded.done之后(function(){ 它会排队 _apiLoaded.resolve(); 删除window.initApi; 没有回复完成功能