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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:03:53+00:00 2026-05-24T02:03:53+00:00

I am implementing a require/load function which retrieves and executes a remote piece of

  • 0

I am implementing a require/load function which retrieves and executes a remote piece of javascript code. It works fine, and I am using a workaround to give it arguments by basically declaring global variables, but I wanted to know what was the best way to pass arguments in this situation. Here is the function that loads the remote script

Module.require = function (moduleName , args){
    if (! Module.has(moduleName)){
        dojo.xhrGet({
            url: 'module.require.php',
            handleAs: "javascript",
            content : {
                module : moduleName
            },
            load: function() {
            },
            error: function(errorMessage) {
                console.log('there was an error with Module.require()');
                console.error(errorMessage);
            }
        });
    }
};

My first question is what context is moduleName executed in when the code stored in moduleName.js is fetched and dynamically executed? If it is in the scope of the function Module.require then I can easily refer to args. If it is executed in the global scope (window) then I know how to declare local variables (anonymous function call (function(){}());) but how do I pass arguments? I hope there is an easy way to do this as I do not wish to pass all the arguments over to the server. Not only is it difficult to parse them via PHP, there code potentially be many arguments.

EDIT: James Khoury mentioned how I can use f.apply() and f.call() to pass arguments, so what I need to know now is what context the script is loaded in on execution. If it’s in the scope of the function, I suppose I can call it like so f.call(this , args);. And if I can do this, is there anyway to call an anonymous function? I ask because I am creating modules which wrap the user code to ensure that all variables the user declares remain local, therefore, it would be best to ensure the wrapper function is also not global.

Thanks

  • 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-24T02:03:55+00:00Added an answer on May 24, 2026 at 2:03 am

    i would look at both function .call and function .apply

    var obj = { x: 15 };
    f.call(obj)
    
    var args = ["hello", 2, {data: "123"}];
    
    f.apply(obj, args);
    

    (this was taken from odetocode.com)

    Then in your function f():

    function f(message, num, dataObj)
    {
        if (this.x)
        {
            alert(this.x);
            // Alternatively you could just do alert(x);
        }
        if(arguments.length > 2)
        {
            dataObj["message"] = ""
            for(var i =0; i < num; i++)
            {
                 dataObj["message"] += message + "\n";
            }
            alert(dataObj.message + "\n" + dataObj.data); 
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a few SharePoint lists that require a file upload , putting
I'm building a system which has the potential to require support for 500+ concurrent
I'm using JDK1.6. When I implement an interface and in the implementing class, if
I'll be implementing this for Node.js (server side Javascript), but this question is about
I am looking in to implementing Url rewriting for our site, using the rewrite
Assuming the you are implementing a user story that requires changes in all layers
Implementing Equals() for reference types is harder than it seems. My current canonical implementation
Implementing a 'sandbox' environment in Python used to be done with the rexec module
When implementing a needle search of a haystack in an object-oriented way, you essentially
When implementing Quicksort, one of the things you have to do is to choose

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.