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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:20:15+00:00 2026-06-05T07:20:15+00:00

I know that a javascript function is perfectly capable of calling other functions. I’ve

  • 0

I know that a javascript function is perfectly capable of calling other functions. I’ve utilized this several times.

Currently I’m working on a script that will find the html elements of a certain tag, and add in a bit of text based on what kind of tag it is.

function foo() {
dealWithH1();
dealWithH2();           
dealWithH3();
etc...          
}

I have done a few searches regarding functions like this and what I can’t seem to find is a definite, consistent answer to whether or not this is good practice. I like this way, because there are a lot of function calls to make, and it keeps it very organized. I just want to make sure before I get too far into it that there isn’t some glaring problem with doing something like this. The function foo() serves no purpose but to be called at onLoad and then call all of these other functions.

Is this okay, or is there a more encouraged way to get this done?

  • 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-05T07:20:16+00:00Added an answer on June 5, 2026 at 7:20 am

    It’s perfectly reasonable to create a pseudo-DSL of operations that are composed of functions.

    Based on your description of what the dealWith... functions do, though, I think you might want to generalize your functions more, something like:

    function foo() {
        tagInsert('h1', 'Text to append to h1 tag');
        tagInsert('h2', 'Text to append to h2 tag');
        tagInsert('h3', 'Text to append to h3 tag');
    }
    

    Now that the essence of the function has been distilled (append text to all tags of a specified type), and the variables of the function have been parameterized (the type of tag and the text to append), you could just as easily do something like:

    var tags = {
        'h1': {
            'en': 'Hello',
            'es': 'Hola',
            'sr@latin': 'Zdravo'
        },
        'h2': {
            'en': 'Goodbye',
            'es': 'Adios',
            'sr@latin': 'Do vidjenja'
        },
        'h3': {
            'en': 'Green',
            'es'; 'Verde',
            'sr@latin': 'Zelena'
        }
    };
    function foo(locale) {
        for(var tag in tags) {
            tagInsert(tag, tags[tag][locale]);
        }
    }
    

    Composability of functions is greatly improved when as much about the operation you will perform is deferred until the function is actually called — you can then use the exact same function to now not just append a fixed set of text to the tags, but to do so in whatever language the user prefers to use.

    This flexibility can of course be taken to absurd lengths and you’d never get anything done, but it’s good to think of your function as a set operator: what is the input to your function (declared explicitly as a variable or implicitly by accessing a global) and what operation is performed to produce the new output set?

    If it doesn’t take much extra effort to write the function in the generic way versus the specific case you’re dealing with, then write it that way and you can re-use that function whenever you need to do a similar action but with different inputs.

    Remember…

    Don’t take my tagInsert definition at face value, I know barely anything about what you’re actually trying to do, and maybe that generalization doesn’t really make sense. The point is that you as the developer should have a better idea of what you’re trying to accomplish.

    If you follow Larry Wall’s Virtues of a Programmer, you should be trying to minimize the amount of extra work you have to do, and your functions will reach the right degree of composability versus complexity.

    Functions calling functions is the whole point of a function — you avoid the need to rewrite it over and over again; just dividing a massive imperative declaration of actions to perform into a series of functions is not the point of a function. What are the repetitive patterns in the imperative code and how can you be as lazy as possible?

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

Sidebar

Related Questions

Currently, I am calling my JavaScript functions using: ScriptManager.RegisterClientScriptBlock(this, typeof(Page), Guid.NewGuid().ToString(), $(function(){$.jGrowl('Hello World');});, true);
I know that javascript, for example supports functions inside of functions, like so: function
I know that there are several ways to define a function in JavaScript. Two
Is there a way to let a javascript function know that a certain parameter
I know that javascript doesn't have pointers in terms of a variable referring to
I know that in Javascript document.location.href = #my_id tells the browser to display the
I know that google's v8 compiles javascript into native machine (binary if I understand
I know that Visual Studio 2008 support JavaScript intellisense as I am using it
I know that you cannot delete a cookie set by another server in javascript.
Is there a set of things that every JavaScript programmer should know to be

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.