Last Updated: February 25, 2016
·
867
· mattcodez

jQuery Deffereds and Resolution Values

If you pass multiple Deffered objects into a jQuery $.when() call, the resolved values will all be passed as individual arguments to the then() callback. Ex.

$.when(
 $.Deferred(
    function(deff){
      deff.resolve(5);
    }
  ), 
 $.Deferred(
    function(deff){
      deff.resolve(7);
    }
 )
).then(function(){
 console.log(arguments);
});

Will output [5, 7] in the console. So presumably the order is based on the order in which the Deffered objects were added to the when list.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside