jQuery中$ .when.apply(null,方法)的含义是什么? [英] What's the meaning of $.when.apply(null, a method) in jQuery?
问题描述
我正在读取jQuery中的延迟对象。有谁能告诉我以下两种调用方式有什么区别?
I'm reading the deferred object in jQuery. Could anyone please tell me what's the difference between following two invoking way?
-
$。when.apply(null,方法).done(function(){success callback})
-
$。when。(方法).done(函数) (){成功回调})
$.when.apply(null, a method).done(function(){success callback})
$.when.(a method).done(function(){success callback})
以上第一种方式适合哪种情况?
And what kind of cases are fit for the first way above?
提前致谢。
推荐答案
$ .when.apply(null,方法)
只有在方法实际上是一个数组或方法调用返回一个数组时才有意义。然后它就像一个 $。when(elements,of,array)
。 请参阅MDN ,了解 apply $的详细说明c $ c>方法。
$.when.apply(null, a method)
only makes sense if a method is actually an array or a method call returning an array. Then it's like a $.when(elements, of, the, array)
. See MDN for a detailed description of the apply
method.
$。当。(方法)
完全没有意义,但我猜你的意思是 $。when(方法)
。在这种情况下,方法应该再次是方法调用,返回延迟对象或指向延迟对象的变量。
$.when.(a method)
makes no sense at all, but I guess you meant $.when(a method)
. In this case a method should again be a method call returning a deferred object or a variable that points to a deferred object.
$。when()
的语法是 $。when(一个或多个,延迟)
- 所以如果你想传递一个数组中的多个延迟,你需要。 apply()
因为您不想将方法调用构建为字符串并使用 eval
(这确实是 evil 强>在这种情况下)。
The syntax of $.when()
is $.when(one, or, more, deferreds)
- so if you want to pass multiple deferreds which are in an array, you need .apply()
since you don't want to build the method call as a string and use eval
(which is indeed evil in this case).
这篇关于jQuery中$ .when.apply(null,方法)的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!