我想我增加了一层复杂性。这是我所拥有的:
;(function($, window, undefined) {
function download() {
var local = {};
local.data = {};
local.data.method = 'getMyData';
local.dataType = 'json';
local.Promise = $.ajax('myComponent.cfc', local);
local.Promise.done(PromiseDone);
local.Promise.fail(PromiseFail);
}
function PromiseDone(result) {};
function PromiseFail(myEvent) {};
})(jQuery, window);
我想做的是这样的:
;(function($, window, undefined) {
var Variables = {};
Variables.Promise = $.Deferred();
function download() {
var local = {};
local.data = {};
local.data.method = 'getMyData';
local.dataType = 'json';
Variables.Promise = $.ajax('myComponent.cfc', local);
}
Variables.Promise.done(function(result) {
});
Variables.Promise.fail(function(myEvent) {
});
})(jQuery, window);
我的目标是扁平化 JavaScript,这样我的函数就不会嵌套。
问:我的想法是否可行,或者是否deferred
需要 aresolve
才能被考虑done
?