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 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

implementing publishActivity in PHP using the REST API using this code: $activity = array(
I'm currently implementing Interceptors using Castle DynamicProxy. I require the interceptor to pick up
I am implementing a validation scheme and am using the bcrypt-ruby gem. require 'bcrypt'
I am implementing a few SharePoint lists that require a file upload , putting
When implementing HTTP services in node.js, there is a lot of sample code like
I am having problem with implementing custom session handler in php. The code: http://pastebin.com/9QV9f22Q
While implementing my own IFilter I found that most likely some consumers will require
I'm using Doctrine 2 in a Zend Framework application and require functionality similar to
I'm implementing a wpf application which display a list of items, and provides the
I'm building a system which has the potential to require support for 500+ concurrent

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.