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

  • SEARCH
  • Home
  • 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 8740443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:07:54+00:00 2026-06-13T11:07:54+00:00

So essentially what I’m trying to do is have a queue of functions that

  • 0

So essentially what I’m trying to do is have a queue of functions that I can add to. These functions are suppose to be drawing things to a canvas like in an requestAnimationFrame.

What I’ve tried:

var drawQueue = [];
function animate() {
    while (drawQueue.length !== 0) {
        drawQueue.shift()();
    }
    requestAnimationFrame(function () {
        animate();
    });
}

With that I was trying to add things like:

drawQueue.push(drawthing(0,0,0,0));

this would just run the function and push undefined to the array, this does how work if you just do this:

drawQueue.push(function () {
    console.log("derp");
});

or

drawQueue.push(functionName); //with no args

The but problem here is that I need to pass arguments to most of the functions I’m calling.

my Second attempt:

var drawQueue = [];
function animate() {
    while (drawQueue.length !== 0) {
        var data = drawQueue.shift();
        Object.apply(data.func, data.args);
    }   
    requestAnimationFrame(function () {
        animate();
    }); 
}

while adding function to the queue like:

drawQueue.push({func: functionName, args: [0,0,0,0]});

but I couldn’t get that to work either, not 100% how to use Object.apply() and what exactly its doing…

So my question is how do I go about making my function queue or is there a better way to do this?

  • 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-13T11:07:55+00:00Added an answer on June 13, 2026 at 11:07 am

    You can’t add something to the queue like this:

    drawQueue.push(drawthing(0,0,0,0));
    

    All that is doing is calling drawthing(0,0,0,0) immediately and pushing the return result from executing the function into the queue.


    Instead, you need to push an actual function into the queue like this:

    drawQueue.push(function() {drawthing(0,0,0,0)});
    

    If you want to just push the function and arguments into the queue separately like this:

    drawQueue.push({func: functionName, args: [0,0,0,0]});
    

    Then, you can pull an item off the queue and execute it like this:

    var item = drawQueue.shift();
    item.func.apply(this, item.args);
    

    When you call function.apply(a, b), it sets the this ptr to the first argument a and then calls the function with whatever arguments are in the b array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

essentially I have a category that you can add comments to, this category shows
Essentially, I have a dynamically generated local HTML form that I would like to
Essentially, I'm looking for a 1D bar-code scanner that I can program, either through
Essentially, I have a binary voting system Like/Dislike. Thee class is called Like It
Essentially, I'd like a special form of an Interface for Exceptions that requires anyone
Essentially, I have a query that is responsible for fetching all records (with specific
Essentially my problem is thus; I have a MVC system that redirects all requests
Essentially what I want to do is impliment a class that can contain a
Essentially, I would like to create a database structure that allows for classifying an
Essentially, my question is this: There are two ways that I have experienced setting

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.