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 7047275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:45:05+00:00 2026-05-28T02:45:05+00:00

In Revealing module pattern of JavaScript how to use setTimeout function? Here is the

  • 0

In Revealing module pattern of JavaScript how to use setTimeout function?

Here is the example.

HTML: <div id="container1"></div>

JavaScript:

var classA = (function() {
    var i = 0;
    var names = ["a", "b", "c", "d", "e", "f"];
    var callTest = function() {
        for (var n in names) {
            window.setTimeout(function() {
                callTest2(names[n]);
            }, 1000);
        }
    };

    var callTest2 = function(pName) {
        $("#container1").append("In callTest   " + i+++" " + pName + "<br>");
        window.setTimeout(function() {
            callTest2(pName)
        }, 10000)
    };

    return {
        testTheTest: function() {
            callTest();
        }
    }
})();

classA.testTheTest();

Framework: jQuery 1.5.2

When I execute the output is:

In callTest 0 f
In callTest 1 f
In callTest 2 f
In callTest 3 f
In callTest 4 f
In callTest 5 f

Instead of:

In callTest 0 a
In callTest 1 b
In callTest 2 c
In callTest 3 d
In callTest 4 e
In callTest 5 f

What am I missing? Where am I doing wrong?

  • 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-05-28T02:45:06+00:00Added an answer on May 28, 2026 at 2:45 am

    I’ve made a few slight modifications to your code which means it now works as you wish it to:

    var classA = (function() {
        var i = 0,
            names = ["a", "b", "c", "d", "e", "f"],
            namesLength = names.length,
            callTest = function() {
                window.setTimeout(function() {
                    callTest2(0);
                }, 1000);
            },
            callTest2 = function(pIndex) {
                if (pIndex < namesLength) {
                    var name = names[pIndex++];
                    $("#container1").append("In callTest   " + i+++" " + name + "<br>");
                    window.setTimeout(function() {
                        callTest2(pIndex);
                    }, 1000);
                }
            };
    
        return {
            testTheTest: function() {
                callTest();
            }
        }
    })();
    
    classA.testTheTest();
    

    Here’s a working example.

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

Sidebar

Related Questions

I'm trying to get my head round the revealing module pattern in javascript. I'm
I stumbled across this post: JavaScript's Revealing Module Pattern . I would like to
I have begun writing my 'class' type JavaScript functions like the Module Pattern or
I am trying to organize my code using the revealing module pattern. I have
I've read about the Revealing Module Pattern and I love it. But what about
I'm making a javascript/canvas game and I saw this example on CSS Tricks. Here's
I am trying to implement Revealing Module Pattern. I need to assign an event
After doing some reading about the Module Pattern, I've seen a few ways of
I asked a question here: Extending javascript literal object which was solved because I
I've been playing around with the revealing module patter. I originally started using the

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.