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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:26:48+00:00 2026-06-13T13:26:48+00:00

I have a function that would use other variables, depending on what has been

  • 0

I have a function that would use other variables, depending on what has been passed.

Like this = ActionBar(slot) slot contains “one”.

and I would like to create a call inside that like object.slot.name but it should convert it before hand to make the command look like object.one.name. Is there a way to do this in javascript/jquery?

I remember vaguely that some other language does this as {slot} or something like that.

Sorry if this question was already asked, I’ve checked google and stackoverflow too, but didn’t find an answer.

Also I’d like to know what’s the proper programming term for this kind of variable passing?

Edited it cause of misunderstandings. I’m looking into OOP js, so object is an object, one is an object, and name is an attribute, but when passing I’m passing “one” as a string to the function.

Tried eval, it doesn’t work while dotted with an object.

Source code:

function disableActionButton(slot){
    $("#"+slot).attr("disabled","disabled")
    gcd = player.slot.gcd*1000
    cd = setInterval(function(){
            gcd = gcd - 10
            $("#"+slot).val(gcd+"ms").css("color","red");
    },10)
    setTimeout(function(){
            window.clearInterval(cd)
            $("#"+slot).removeAttr("disabled").css("color","black").val(player.slot.name);
    }, player.slot.gcd*1000)    
}
  • 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-13T13:26:49+00:00Added an answer on June 13, 2026 at 1:26 pm

    It’s really unclear what your current structure is (much clearer now you’ve posted code, see “update” below), but fundamentally the way to do this sort of thing in JavaScript is to have a container object. (If you don’t already have one, introduce one.) Then slot can refer to a property of that object, like this:

    var container = {
        one: "This is one",
        two: "This is two"
    };
    
    // ...
    
    function foo(slot) {
        console.log(container[slot]);
    }
    
    // ...
    
    foo("one"); // ends up logging "This is one"
    foo("two"); // ends up logging "This is two"
    

    This works because the container object has properties, which in JavaScript can be referred to in two different ways:

    1. Using dot notation and a literal name, e.g. container.one, or

    2. Using bracketed notation and a name in a string, e.g. container["one"].

    They’re exactly equivalent except where the property name comes from. And of course, in the second case, the property name needn’t be a literal string, it can be the result of any expression, including a variable reference (e.g., you can get the name from slot).

    This works with all object properties, including properties that refer to functions. I mention this only because you mentioned functions in your question, so if you need to, you can do this:

    function foo(slot) {
        container[slot]();
    }
    

    …which calls the function on container that the property with the name held by the slot argument. So if slot is "one", it does container.one().


    Update:

    Your source directly echos the container example above, just apply the above to it:

    function disableActionButton(slot){
        $("#"+slot).attr("disabled","disabled")
        // ---------v----v---- here
        gcd = player[slot].gcd*1000
        cd = setInterval(function(){
                gcd = gcd - 10
                $("#"+slot).val(gcd+"ms").css("color","red");
        },10)
        setTimeout(function(){
                window.clearInterval(cd)
        // ------------------------------------------------------------ and here--v----v
                $("#"+slot).removeAttr("disabled").css("color","black").val(player[slot].name);
        // ------v----v------- and here
        }, player[slot].gcd*1000)    
    }
    

    Or, rather than looking up the slot data each time, grab it once and reuse it:

    function disableActionButton(slot){
        // Grab it once...
        var slotdata = player[slot];
    
        $("#"+slot).attr("disabled","disabled")
        // ---vvvvvvvvv--- then use it
        gcd = slotdata.gcd*1000
        cd = setInterval(function(){
                gcd = gcd - 10
                $("#"+slot).val(gcd+"ms").css("color","red");
        },10)
        setTimeout(function(){
                window.clearInterval(cd)
                $("#"+slot).removeAttr("disabled").css("color","black").val(slotdata.name);
        }, slotdata.gcd*1000)    
    }
    

    There’s no special name for this. You’re passing a property name into a function, and the function is looking up the property on the player object using that name. In some other languages this might be called “reflection” but the term doesn’t really apply to dynamic languages like JavaScript.

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

Sidebar

Related Questions

I have a function that I use on index.php page and I would like
I have this function that I would like to condense into some iterator. How
I would like to have a function that can wrap any other function call.
I would like to have a mapping function that does this: public static void
I have a function that I would like to return 0 if a certain
I'd like to write a function that would have some optional code to be
I have a function that is side-effect free. I would like to run it
I have a dataframe and I would like to apply a function that takes
PHP: I have made up a function that returns an array. I would like
I have three classes that all have a static function called 'create'. I would

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.