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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:46:11+00:00 2026-06-09T23:46:11+00:00

I am working on an application using RequireJS AMD loading method. I have my

  • 0

I am working on an application using RequireJS AMD loading method.

I have my modules dynamical picked up from a configuration file into an array

var amd_modules = ["module1", "module2","module3"]

now I have my requireJS code

require(amd_modules, function(result) {
console.log("All modules loaded");
}

Now, the result variable shows the first module which is “module1”. How can I get other modules also into variable inside the function() parenthesis.

For eg,

require(amd_modules, function(module1, module2, module3) { //
}

I can’t write the above hardcoding because the number of dynamic variables are not known until run time. Do let me know how I can catch the objects dynamically inside the function.

Thx

  • 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-09T23:46:13+00:00Added an answer on June 9, 2026 at 11:46 pm

    Simply use arguments:

    require(amd_modules, function() {
        console.log("All modules loaded");
        // arguments should now be an array of your required modules
        // in the same order you required them
    });
    

    However, unless you have a good reason to do so, you probably want to rethink the way you are designing your application – even at the topmost level your modules should be simple and testable. Having a widely varying number of dependencies indicates that you are probably trying to do to much in your callback function. Break each code path out into its own module and then switch only on your top-level dependency instead. In code:

    // Instead of this:
    require(amd_modules, function() {
        console.log("All modules loaded");
        if (complex_condition_A) {
            var x = arguments[0],
                    y = arguments[1],
                    z = arguments[2];
            // Do things with x, y and z
        }
        else if (complex_condition_B) {
            var a = arguments[0],
                    b = arguments[1];
            // Do things with a and b
        }
        else {
            // et cetera, et cetera, et cetera
        }
    });
    
    
    // Do this instead
    var rootModule;
    if (complex_condition_A) rootModule = "A";
    else if (complex_condition_B) rootModule = "B";
    else rootModule = "C";
    require(rootModule, function(root) {
        // Root has the same API, regardless of which implementation it is
        // This might be as simple as an `init` method that does everything
        // or as complex as, say Facebook's API, but with different libraries
        // loaded depending on the platform the page is loaded on
        // (IE vs. Android for example).
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working application using python and zeromq and I would like to
I'm currently working on web application using VB in ASP.NET. Right now I have
Greetings, I'm working in windows application using C#. I have typed-dataset called packetsDBDataSet and
I'm working on an application using MEF (specifically, MEF 2 Preview 5 ), and
I am working on window application using c# . i want to show my
I am working a java application using H2 Database in embedded mode. My Application
I am working on an application using Spring 3 and Hibernate 3.5 with Java
I am working on big application build using ASP.NET which was started 1.5 years
I'm working on a security camera application using the webcam that takes a photo
I am working on a wpf application using PRISM. This is my first ever

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.