Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8357599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:31:48+00:00 2026-06-09T10:31:48+00:00

I have an object full of functions like so: var functions = { fun1

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T10:31:50+00:00Added an answer on June 9, 2026 at 10:31 am

    Wow… that was an exercise—$.Deferred() was a little hard to get my mind wrapped around, but I got it all working how I wanted! I don’t know how streamlined this is—perhaps others can make it more efficient.

    The gist of it is to create a chain of deferreds using .pipe().

    EDIT: My code (below) does not accommodate less than 2 objects in the reference key list. I updated the jsfiddle to work with key lists of any size.


    You can see all of the following working on JSFiddle Here: http://jsfiddle.net/hBAsp/3/


    Here’s a step-by-step of how I solved it:

    1. Start with an object full of functions and an array of reference keys (in the order you want them processed). The functions should expect to receive a deferred object to resolve on completion:

      var obj = {
          one: function(dfd){
              /* do stuff */
              dfd.resolve();
          },
          two: function(dfd){...},
          three: function(dfd){...},
          etc...
      };
      var keys=['one','two','three', etc...];`
      
    2. Create main deferred wrapper passing the promise into the initialization function. We’ll be adding the code to the function as we go:

      var mainDeferred = $.Deferred(function(mainDFD){
      
    3. Inside of that initialization function, create an array of deferreds, manually creating the first deferred object:

      var dfds = [$.Deferred()];
      
    4. Next, use a for loop to go through the second through the next-to-last items in our key list. We will be:

      1. creating a deferred object for each item we step through
      2. setting up an anonymous function that will run the key-associated function from our obj, passing to it for resolution our newly created Deferred object
      3. piping that newly-created function onto the previously created Deferred object (which is why we had to create the first one manually)
      4. You must use an enclosed loop in the for list to get past JavaScript scoping problems

        for (i=1; i<keys.length-1; i++){
            (function(n){
                dfds.push($.Deferred());
                dfds[i-1].pipe(function(){
                    obj[keys[n]].call(this,dfds[n]);
                });
            })(n);
        };
        
    5. Manually create the last anonymous function and pipe it onto the next-to-last deferred object in our list. We do this one manually because we want to pass to it the main deferred object for resolution so that the whole shebang will fire as complete as soon as the last process has run:

      dfds[keys.length-2].pipe(function(){
          obj[keys[keys.length-1]].call(this,mainDFD);
      });
      
    6. Now that our whole pipeline is built, all we have to do is fire off the first object and assign it the first deferred for resolution:

      obj[keys[0]].call(this,dfds[0]);
      
    7. Just have to close up our main deferred initialization function (this will all fire as soon as the deferred is created:

      });
      
    8. Now we can also pipe a function to the main object to run after all of our previous elements have run:

      mainDeferred.pipe(function(){
          /* do other stuff */    
      });
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array full of objects from the same class. I'd like to
I have an NSArray full of NSDictionary object. This structure is built from a
I have an object animating, which I would like to start fading out, after
I have a FormPanel that looks like this: var simple_form_left = new Ext.FormPanel({ frame:true,
I have a JSON string array of objects like this. [{id:4,rank:adm,title:title 1}, {id:2,rank:mod,title:title 2},
I have a problem with Javascript forcing the [object DOMWindow] into an function I
I have an array with days in it. Each day is an object, for
I have the following code (function($) { // carousel var Carousel = { settings:
I have created a header file and a corresponding .c file full of functions
I have a vimeo flash object hidden like so CSS: #banner-vid-link div.object, #mainVideo, #blackSheet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.