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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:32:29+00:00 2026-06-17T11:32:29+00:00

(Not sure if I am using the correct terminology, in Python that is called

  • 0

(Not sure if I am using the correct terminology, in Python that is called a tuple. Hope it makes sense.)

I would like to refactor the following method. The only difference is the enddate/startdate respectively, therefore there is no need to repeat the code.

function datepicker_reload(source, isPast){
    if(isPast){
        $(source).find('.date_picker').datepicker({ 
            endDate: new Date(),
            format: $('#locale').text(), 
            weekStart:1, 
            calendarWeeks:'True',   
            autoclose: 'True', 
            todayHighlight: 'True' 
        });
    }
    else{
        $(source).find('.date_picker').datepicker({
            startDate: new Date(), 
            format: $('#locale').text(), 
            weekStart:1, 
            calendarWeeks:'True',   
            autoclose: 'True', 
            todayHighlight: 'True' 
        });
    }
}

I was wondering if I could put the common values as a tuple together:

var options = { format: $('#locale').text(), 
            weekStart:1, 
            calendarWeeks:'True',   
            autoclose: 'True', 
            todayHighlight: 'True'  };

Then add the one additional keypair in there: (However this step seems to be completely off, how do i achieve it?)

if(isPast)
   options += {endDate: new Date()}
else
   options += {startDate: new Date()}

and then pass the whole tuple to the function:

$(source).find('.date_picker').datepicker(options);

is this possible?

  • 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-17T11:32:31+00:00Added an answer on June 17, 2026 at 11:32 am

    The correct syntax in javascript for what you’re trying to do is:

    if(isPast){
       options["endDate"] = new Date();
    }else{
       options["startDate"] = new Date();
    }
    

    You are just setting an object’s property.

    Note: options.endDate = new Date(); (dot notation) would also work, however it does not work if the property you’re adding to the object contains spaces, operators, or other special chars.

    Note 2: I’m assuming you don’t really want to clone the object but just to add a property to it, javascript objects are mutable.

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

Sidebar

Related Questions

I'm not 100% sure that I'm using the correct terminology or if I'm leaving
I'm not sure if I'm using the correct terminology, so please correct me if
I have a generic (I'm not too sure if that's the correct terminology..) method
I'm not sure if I'm using the correct terminology to describe my questions so
I'm not sure I'm using all the correct terminology here so be forgiving. I
I'm not sure that I'm using the correct language here so I will give
Not sure if I am using the correct term, but it's not child/parent since
Im not sure how to word this, or what the correct terminology is. Hopefully
I am not sure if the terminology is correct, but I am looking for
I'm not sure if I'm using the correct term here, but let's say I

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.