$.when.apply($, $.map(array, someFunction(x){})) 的返回值?

Returned value for $.when.apply($, $.map(array, someFunction(x){}))?

getTickets 函数返回什么?

function getTickets(needsTickets) {
    return $.when.apply($, $.map(needsTickets, function(x) {
        return function(x) { return $.ajax() } ;
    }));
}

$.whenreturns一个promise

可用于附加异步回调。它们将在 $.when 执行结束时执行。

$.when(...).done(function() {
    console.log('everything is ok');
}).fail(function() {
    console.log('not ok');
}).always(function() {
    console.log('always called');
});

apply 是函数的 javascript 内置函数。它可用于调用带有参数数组的函数。这两行做同样的事情:

myFunction.call(null, ['test', 'test 2']);
myFunction('test', 'test 2');

让我们分析一下发生了什么:

$.when 的结果是一个承诺,这就是返回的内容。

$.when 不接受数组作为参数,因此要处理您需要做的一系列承诺:

$.when.apply( context, promiseArray);

承诺数组正在由 $.map

创建