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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:11:50+00:00 2026-06-17T15:11:50+00:00

I am not sure if this is possible. I would like to pass in

  • 0

I am not sure if this is possible. I would like to pass in a function name as parameter like this

loadContent("http://test.com/", specialFunction);

specialFucntion is just a string :

function loadContent(href, functionIWant){
    $.ajax({
        type: "GET",
        url: href,
        dataType: "json",
        success: function(res, textStatus, xhr) {
            helper();
            functionIWant + "()"; //So this would be treated as function
                                  //and it actually calls specialFunction()
                                  //is it possible for this?
        }
    });
}

How do I achieve this?

ADD-ON

Let’s say, I would pass in an array of function names, how do I call it?

for(var i = 0; i < functionIWant.length; i++){
   functionIWant[i]; // how? appeciate a lot :)
}
  • 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-17T15:11:52+00:00Added an answer on June 17, 2026 at 3:11 pm

    You can just do it with functionIWant()

    Example using your provided snippet:

    function loadContent(href, functionIWant)
    {
        $.ajax({
            type: "GET",
            url: href,
            dataType: "json",
            success: function(res, textStatus, xhr) {
                helper();
                functionIWant();
            }
        });
    }
    

    For your addendum

    Assuming the following three functions you want to call

    function foo() {alert("Foo")}
    function bar() {alert("bar")}
    function baz() {alert("baz")}
    

    The best I can recommend if you’re passed an array of function names as strings is to follow the advice here. Basically, you could just do it like this:

    // Assuming FunctionIWant is an array of strings that represent function names
    FunctionIWant = ["foo","bar","baz"];
    
    ...
    
    for(var i=0;i<FunctionIWant.length;i++)
        window[FunctionIWant[i]]();
    

    If, however, FunctionIWant is an array of actual functions, for example, you can simply iterate over them and call them individually like so:

    FunctionIWant = [foo,bar,baz] // note, these are not strings
    
    for(var i=0;i<FunctionIWant.length;i++)
        FunctionIWant[i]();
    

    In most cases, you’ll be better off assigning the function rather than as a string

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

Sidebar

Related Questions

I would like to pass a comparer into a function and not sure if
Not sure this is possible, but looking to write a script that would return
I'm not sure if this possible but probably is fairly simple. I've made a
I'm not sure this is possible, but in ruby, you can dynamically call a
I'm not sure this is possible, but is there a syntax to be used
Not sure if this is possible: I want to use datatables to manipulate my
Not sure if this is possible. I want to grab the latest X stories
Not sure if this is possible in one Makefile alone, but I was hoping
I'm not sure this is even possible but I know if it is, the
I'm not sure if this is possible (complete non-flash developer speaking), but we have

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.