Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 450
hippietrail Avatar asked Jun 15 '16 07:06

hippietrail


People also ask

What is ES6 promise in JavaScript?

ES6 Promise is the easiest way to work with asynchronous programming in JavaScript. Asynchronous programming includes the running of processes individually from the main thread and notifies the main thread when it gets complete. Prior to the Promises, Callbacks were used to perform asynchronous programming.

What are promises in JavaScript?

Promises are a way to implement async programming in JavaScript (ES6). A Promise will become a container for future value. Like if you order any food on any site to deliver it to your place that order record will be the promise and the food will be the value of that promise.

What is the difference between ES5 and ES6?

Object manipulation is time-consuming in ES5. Object manipulation is less time-consuming in ES6. 7. In ES5, both function and return keywords are used to define a function. An arrow function is a new feature introduced in ES6 by which we don’t require the function keyword to define the function.

What are the two types of callbacks for promises in JavaScript?

Callbacks to Promises: There are two types of callbacks which are used for handling promises .then () and .catch (). It can be used for handling promises in case of fulfillment (promise is kept) or rejection (promise is broken). .then (): Invoked when a promise is kept or broken.


1 Answers

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.

like image 126
neciu Avatar answered Sep 19 '22 12:09

neciu