jQuery Deferred with an array of functions

Viewed 4063

I have an object full of functions like so:

var functions = {
    fun1 : function(){ ... }
    fun2 : function(){ ... }
    fun3 : function(){ ... }
};

The object keys are all referenced inside an array like so:

var funList = ['fun1','fun2','fun3'];

I have been using the array to run through all of the functions:

$.each(funList, function(i,v){
    functions[v].call(this, args);
});

My problem is this, I need some way to defer the running of all of the functions such that:

  1. In the $.each loop, the functions run serially
  2. Some method to defer the running of subsequent code until after all functions in the array/object have completed.

I've read that I should be using the $.map method for this, but I'm having a hard time wrapping my mind around it.

2 Answers
Related