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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:46:51+00:00 2026-05-13T18:46:51+00:00

How to solve huge hierarchy in JavaScript function? With Switch? Thank you. (Sorry, I

  • 0

How to solve huge hierarchy in JavaScript function? With Switch? Thank you.

(Sorry, I am not native English speaker.)

function do(param1, param2) {

  switch(param1) {

    case "write":

      /* another switch for param2 */

    break;

    ...

  }

}

Example calls:

do('write','house'); // write house
do('return','house'); // return house 
etc.
  • 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-13T18:46:51+00:00Added an answer on May 13, 2026 at 6:46 pm

    Create an object that names functions the way you want:

    var obj = {
        "write": function(param) {
            //Write param
        },
        "return": function(param) { //Enclosing the function name is quotes lets you use reserved words as function names
            //Return param
        }
    };
    

    You could write your function to simply look up the members in that object using array notation:

    function do(param1, param2) {
        obj[param1](param2);
    }
    

    Doing it this way would be much easier to maintain and would be much more scalable. However, I wouldn’t even do it that way. I’d replace the do function with the object itself and then you could simply call these members the old fashioned way:

    obj.write("Something");
    

    Or, if the name return causes problems and you really want to use it:

    obj["return"]("Something");
    

    There’s alot of power and flexibility in JavaScript objects and functions.

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

Sidebar

Related Questions

I inherited a huge, bulky MS Access database and am assigned to solve a
I have a huge string of multiple URLs in javascript which is of the
I have a difficult case to solve regarding the Maven automated projects versioning, I
Solve this equation for x, (1 + x)^4=34.5 . I am interested in the
To solve some problem I need to compute a variant of the pascal's triangle
Please solve that mystery to me.. I'm having the simplest layout of webform, meaning
Scenarios I need to solve with task scheduler in Windows Server 2008: (#1) task
I'm trying to solve a codechef beginner problem - Enormous Input Test . My
Trying to solve an issue for someone else and instead have run into my
I am attempting to solve Project Euler problem 10 where the user is asked

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.