jQuery.when()和ES6的Promise.all()之间有什么区别? [英] What are the differences between jQuery.when() and ES6's Promise.all()?

查看:1074
本文介绍了jQuery.when()和ES6的Promise.all()之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习了jQuery的承诺,然后几年没有做太多的编程。现在我想使用原生的ES6承诺做一些事情。



承诺稍后弯曲我的头。现在,两者都非常生锈,而且jQuery承诺,其他承诺图书馆和新的本机JS承诺之间存在着微小和重大的差异,当我尝试使这些东西工作时,我的头更加弯曲。 >

好像 jQuery.when () Promise.all() 做同样的事情,但是我们应该记住一些重要的区别吗?

解决方案

Promise.all() take array of 承诺或简单的 JS对象作为参数,所以您需要通过索引访问结果。



jQuery.when()采用多个参数,这些参数是简单的 JS对象 jQuery Deferred ,所以你可以通过变量名来访问你的结果。


I learned promises with jQuery and then didn't do much programming for a couple of years. Now I want to do some stuff using native ES6 promises.

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.

It seems like jQuery.when() and Promise.all() do the same thing, but are there some important differences we should keep in mind?

解决方案

Promise.all() takes Array of Promises or plain JS objects as argument so you need to access results by index.

jQuery.when() takes multiple arguments which are plain JS objects or jQuery Deferred, so you can access your result by variable name.

这篇关于jQuery.when()和ES6的Promise.all()之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆