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

The Archive Base Latest Questions

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

Following my last thread ( here ), I think I’ve pin-pointed the problem. However,

  • 0

Following my last thread (here), I think I’ve pin-pointed the problem.

However, I’m getting a headache trying to understand why this is occurring.

Context: I have an Object called “Schedule” within which I’m creating 52 “week” Objects. Each week has functions to return the start and end dates in a MySQL format, the JS date Object and a label. More details in previous post.

It works perfectly, apart from when I’m trying to initiate the “EndDate”.

/* --- LEAP.Schedule.week Object --- */

LEAP.Schedule.week = function(n_date, n_week){

    this.week = n_week;

    this.date = n_date;

    this.year = this.date.getFullYear();

    this.month = this.date.getMonth();

    this.month += 1;

    this.day = this.date.getDate();

    alert("BEFORE " + this.date.getDate());

    this.end_date = this.setEndDate(this.date);

    alert("AFTER " + this.date.getDate());

};

LEAP.Schedule.week.prototype.setEndDate = function(date) {

    var ret_date = date;

    ret_date.setDate(ret_date.getDate() + 6);

    return(ret_date);

}

Using the alerts either side of “this.setEndDate” being run, I can see that “this.date” is being incremented every time “setEndDate” is being run.

I don’t want that to happen: I want “this.date” to stay as the date being passed into the week Object, and I want a separate variable called “this.end_date” which is basically this.date plus six days.

I’m presuming this is a referencing issue. I found this article: http://www.snook.ca/archives/javascript/javascript_pass/ but truth be told I don’t understand it… 🙂

Could anyone enlighten me?

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

    I think it’s because you’re passing “this.date” through to setEndDate each time, so when you run ret_date.setDate you are doing it to this.date. This is because “date” is an object whose reference is being passed around.

    You should be able to change it as such:

    var mydate = new Date(this.date);
    this.end_date = setEndDate(mydate);
    

    The mydate object will now be modified, which won’t affect your code.

    Better still, you could just tell the set end date to change the this.end_date, based on this.date and you shouldn’t need to pass anything around!

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

Sidebar

Related Questions

SOLVED in the last answer im getting following error, dunno where and why? cause
The following function is trying to find the nth to last element of a
I am trying to understand the state of a Thread object after the thread
Following from my last question which @Jon Skeet gave me a lot of help
I have the following String First Last <first.last@email.com> I would like to extract first.last
I've tried a variety of combinations, the following being my last attempt: Addtype text/vnd.wap.wml
Following on from my last question What is a Stub , I would really
Following up on my last year's question on documentation, I now want to get
The last line in the following line keeps on generating the warning C4552: '<='
The following code gives a segmentation fault on the last line require 'rubygems' gem

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.