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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:46:38+00:00 2026-06-05T01:46:38+00:00

I passed a function(which itself has a parameter let’s say para) as a parameter

  • 0

I passed a function(which itself has a parameter let’s say para) as a parameter into another function function b() and how to get the parameter para.

here is the simple example

<input type="button" onclick="sometest3()" value="Run test">

<script>
function sometest3() {

    // pass an anonymous function as a parameter which has
    // its own parameter "client"
    sometest('connection',function(client){client.getInfo();}) 
}


function sometest(eve,func) {

     // get this function's parameter which is "client" and pass
     // a reference of sometest2 to it. so in the callback I can use
     client.getInfo(); 
}


function sometest2() {
   this.getInfo=function (){alert("get it");};
}
</script>
  • 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-05T01:46:39+00:00Added an answer on June 5, 2026 at 1:46 am

    You can’t given the code you’ve posted. The anonymous function passed to sometest is held as a local variable that is inaccessible to functions outside its scope.

    If you want sometest to access client, you must pass it, the following uses local variable:

    function sometest3() {
    
        var client = {getInfo: function(){ /* whatever */}};
    
        sometest('connection', function(client){client.getInfo();}, client);
    }
    
    
    function sometest(eve, func, client) {
    
        // The client object has been passed from sometest3
        func(client);
    
    }
    

    Or you could make it available to both functions in a closure or global variable, or property of some object accessable to both functions (essentially these same thing). Your choice.

    e.g. using a closure:

    var foo = (function() {
        var client = {getInfo: function(){ /* whatever */}};
        return {
            sometest3: function() {
                foo.sometest('connection', function(obj){obj.getInfo();}, client);
            },
    
            sometest: function(eve, func, client) {
                // The client object has been passed from sometest3
                func(client);
            }
        };
    }());
    

    Then call it as foo.sometest3().

    Edit

    Added call

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

Sidebar

Related Questions

How do I cast a parameter passed into a function at runtime? private object
I try to call a function which passed as function pointer with no argument,
I have a function which checks the passed value and returns false or true,
I want to write a function which can validate a given value (passed as
Is there any way, given a function passed as a parameter, to alter its
Let's say I have something like this: abstract class Parent { protected function foobar($data)
So, let me see if I get this clearly or not. When we say
... // result is a JSON data passed to this function from outside var
Possible Duplicate: Finding the Variable Name passed to a Function in C# In C#,
Possible Duplicate: Determine original name of variable after its passed to a function. I

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.