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

  • Home
  • SEARCH
  • 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 6585421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:39:41+00:00 2026-05-25T16:39:41+00:00

Problem : A Javascript function needs few parameters to work with: function kick(person, reason,

  • 0

Problem:
A Javascript function needs few parameters to work with:

function kick(person, reason, amount) {
    // kick the *person* with the *amount*, based on the *reason*
}

As there’s no way to do function overloading in JS like how you do in Java, if it needs to be designed for easy future improvement (parameters adding), it can be written as:

/* Function Parameters pattern */
function kick() {
    // kick the person as in *arguments[0]*, with the amount as in *arguments[1]*,
    // based on the reason as in *arguments[2]*, with the strength as in *arguments[3]*
}

or

/* Object Configuration Pattern */
function kick(config) {
    // kick the person as in *config.person*, with the amount as in *config.amount*,
    // based on the reason as in *config.reason*, with the strength as in *config.strength*
}

I do know that Object Configuration Pattern allows augmentation for any default properties.

So, the question is:
If I don’t need to augment any properties with the parameters, is there any significant reason of using any one of the proposed solutions as opposed to the other?

  • 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-25T16:39:42+00:00Added an answer on May 25, 2026 at 4:39 pm

    Using an object has a few advantages:

    1. The code is more readable

    Consider the following two calls:

    kick({user: u,
          reason: "flood",
          log: true,
          rejoin: false,
          timeout: 60000,
          privmessage: true});
    
    kick(u, "flood", true, false, 60000, true);
    

    and imagine someone else reading the call. What is the first true? Note also that yourself in a few month would be in the same exact position (not remembering what is the fourth parameter to kick is very similar to not knowing it).

    2. You can tunnel parameters

    With the object approach you can pass a function a set of parameters that this function must use to call another function

    function kickgroup(users, parms) {
        for (var i=0; i<users.lenght; i++) {
            var uparms = Object.create(parms);
            uparms.user = users[i];
            kick(uparms);
        }
    }
    

    Note also that in the arguments case you don’t need to punish yourself by using arguments[x] syntax. You can just declare the parameters and add them as the function evolves: any parameter that has not been passed will be set to undefined (and if you need you can still access arguments.length to distinguish if the caller explicitly passed your function undefined).

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

Sidebar

Related Questions

I've run into a problem where I make changes to a few JavaScript files
Is there a cross-browser way from a Javascript event handler to determine whether the
There is a JavaScript function, of which I have zero control of the code,
A few months ago i made a Javascript library for my work, and now
Javascript onclick needs to be clicked twice for function to run. I need it
I have a problem with a javascript set of functions that I made. This
I have problem in some JavaScript that I am writing where the Switch statement
I have a problem with a javascript error: $(#slider) is undefined How can i
Hi I have a problem with a javascript string var foo = \<a href=javascript(foo('a','b'))>test</a>\
My problem is a bit more complex than using the following simple JavaScript code:

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.