简体   繁体   English

jQuery.when()和ES6的Promise.all()之间有什么区别?

[英]What are the differences between jQuery.when() and ES6's Promise.all()?

I learned promises with jQuery and then didn't do much programming for a couple of years. 我用jQuery学习了promises,然后在几年内没有做太多的编程。 Now I want to do some stuff using native ES6 promises. 现在我想用原生的ES6承诺来做一些事情。

Promises bent my head a little back then. 承诺在那时稍稍弯下腰。 Now with both being quite rusty on top of that and there being minor and major differences between jQuery promises, other promise libraries, and the new native JS promises, my head gets even more bent when I try to get this stuff working. 现在两者都非常生疏,并且jQuery承诺,其他承诺库和新的原生JS承诺之间存在细微差别,当我试图让这些东西起作用时,我的头脑变得更加弯曲。

It seems like jQuery.when() and Promise.all() do the same thing, but are there some important differences we should keep in mind? 似乎jQuery.when()Promise.all()做同样的事情,但是我们应该记住一些重要的差异吗?

Promise.all() takes Array of Promises or plain JS objects as argument so you need to access results by index. Promise.all()Array of Promises或普通JS objects作为参数,因此您需要通过索引访问结果。

jQuery.when() takes multiple arguments which are plain JS objects or jQuery Deferred , so you can access your result by variable name. jQuery.when()接受多个参数,这些参数是普通的JS objectsjQuery Deferred ,因此您可以通过变量名访问结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM