Date prototype problem

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

Why would this code...

Date.prototype.addDays=function( days ) {
this.setDate( this.getDate()+days );
}

....break the Date constructor? If I don't include it, everything
is fine. If I do, alert( new Date() ); gives me an empty string.
What in the holy heck gives? (Sorry - I just wasted half an hour
tracking down a problem caused by changing an == null to an ===
null, so I could be more cheerful)
 
L

Lasse Reichstein Nielsen

Christopher Benson-Manica said:
Why would this code...

Date.prototype.addDays=function( days ) {
this.setDate( this.getDate()+days );
}

Who knows. What browser are you using? Do you have a small, self
contained example that shows the problem?

I see no problem in Opera 8, IE 6 or Firefox 1.4.


/L
 
L

Lasse Reichstein Nielsen

YD said:
Lasse Reichstein Nielsen a écrit :


Firefox 1.4! Future is now ;-)

"What's a factor 10 between friends" (quoting a Computer Science teacher :)

/L
 
C

Christopher Benson-Manica

Lasse Reichstein Nielsen said:
Who knows. What browser are you using? Do you have a small, self
contained example that shows the problem?

IE6, and no, I tried distilling it down and the problem went away. I
didn't post with much hope of solving the problem, unfortunately.
 
F

fox

Christopher said:
IE6, and no, I tried distilling it down and the problem went away. I
didn't post with much hope of solving the problem, unfortunately.

There didn't seem to be a problem with your code...

I tried your exact code in IE6 -- no problems whatsoever. (In my case,
IE started with "fresh" code.)

I have, every so often, noticed that IE6 has a tendency to "get stuck"
when editing/changing JScript code. It happened with my post concerning
"Array_unique". When testing repeatedly, it would pass the last line of
the prototyped function's statement without error (without testing if
there was an array length, i.e., if there existed more than one indexed
array item). The next day, when I started IE "fresh" and tried the page
again (because I was pretty sure that line should not have worked for
"associative" only arrays) -- sure enough, it started kicking the
errors. Also, I always use control-refresh, which is supposed to force a
reloading of the page from the "server" (and view source WILL show the
changed code), and still IE will run something incorrectly. I also
notice this situation happens more frequently when in: Tools > Internet
Options > Temporary Internet Files > Settings is set to anything other
than "Every visit to the page". Setting this option definitly helps when
developing JScript -- but is often inconvenient when surfing.

If you run into seemingly absurd situations like this [your original
post code was exceedingly simple and clear -- "obvious"] and your code
should, without question, absolutely work, try closing all instances of
IE and restarting fresh, or changing the above mentioned option while
you develop your code [still use control-refresh as you work!].

Now, I'm probably going to get slammed for these comments. I have no
absolute proof and cannot make the situation recreatable in any specific
circumstances. Maybe others have noticed, or almost noticed, the same
situation, I don't know. The array_unique code as being "read into" IE
and the first version I posted was working without error when I posted
it (I was double checking with View Source to make sure it was the
"right" code) . The errors did not start occuring until the browser was
restarted. I currently have my temporary internet files setting options
set to Automatcally.

[Take with a grain of salt, 2 aspirin, and don't call me in the morning]
 
T

Thomas 'PointedEars' Lahn

Christopher said:
Lasse Reichstein Nielsen said:
Who knows. What browser are you using? Do you have a small, self
contained example that shows the problem?

IE6, and no, I tried distilling it down and the problem went away.
[...]

Would you care to share your insights, even if it would be only for
the purpose of politeness?


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top