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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:25:30+00:00 2026-05-22T03:25:30+00:00

How can you invoke a function in JavaScript, while passing in arguments, using a

  • 0

How can you invoke a function in JavaScript, while passing in arguments, using a function pointer?

Example:

function foo (a, callback) {    
        jQuery.post('/soon/check.json', { var:a }, function(resp) {
             callback(resp);
    }); 
}

function process_json(resp) {
  // Do something with resp
}

foo(bar, process_json);

process_json never gets invoked. Looking in Firebug, the string process_json is getting passed into foo, but I assumed this represents a pointer to the function process_json.

In Javascript, is it not possible to invoke functions via pointers and pass in arguments?

  • 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-22T03:25:31+00:00Added an answer on May 22, 2026 at 3:25 am

    In Javascript, is it not possible to invoke functions via pointers and pass in arguments?

    It most certainly is possible to do this. Everything about your code looks just fine to me. Are you sure that the $.post() callback (the anonymous function) is being called? Is bar undefined when foo is invoked?

    To clarify, we need to invoke a function using a string — not a function pointer. Is this possible?

    Yes. If the function is defined globally, you can invoke it as a property on the window object, like so:

    function foo () { /* snip */ }
    
    var fn_name = 'foo';
    
    window.foo();       // works
    window['foo']();    // works
    window[fn_name]();  // also works
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a function in Javascript (with jQuery, if you want): function
I call function in .NET using Reflection (Method.Invoke). If an error occurs inside this
After creating a instance of a class, can we invoke the constructor explicitly? For
How can I dynamically invoke a class method in PHP? The class method is
In spring you can initialize a bean by having the applicationContext.xml invoke a constructor,
If you have Mathematica code in foo.m, Mathematica can be invoked with -noprompt and
Can I access spring bean that exposed using http invoker (server) from GWT application
In Javascript, if we are aliasing a function (or, assign a reference to a
In javascript there's this sweet, sweet function window.setTimeout( func, 1000 ) ; which will
I have a small question in JavaScript. Here is a declaration: function answerToLifeUniverseAndEverything() {

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.