FAO Robert: Why won't this code work part 2

F

FayeC

Ok....I made the appropriate additions to the spaces commented and this is
what I got now:

currentDate = new Date;
today =
currentDate.getDate()+"/"+currentDate.getMonth()+"/"+currentDate.getYear();
cookie = sharedObject.getLocal("date");
if (cookie.data.expire == undefined) {
cookie.data.expire =
(currentDate.getDate()+7)+"/"+currentDate.getMonth()+"/"+currentDate.getYear
();
cookie.data.today = today;
} else {
sepToday = cookie.data.today.split("/");
sepExpire = cookie.data.expire.split("/");
if (Number(sepToday[0]) >= Number(sepExpire[0]) && Number(sepToday[1]) <=
Number(sepExpire[1])) {
this.stop(); //stay stopped on frame 1
} else {
this.gotoAndPlay(2); //Play movie
}
}
cookie.flush();

How can I test it?
I mean....I tried searching for a file called date.sol here but couldn't
find it.
Is there a way I can sort of reset the system to test the script's
functionality?
And to change the expiration period I understand I need to change the number
here:
currentDate.getDate()+7
Am I correct?

Thanks in advance for your big help :)

FayeC
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sun, 5
Sep 2004 11:38:18, seen in FayeC
Ok....I made the appropriate additions to the spaces commented and this is
what I got now:

currentDate = new Date;

Should be new Date() , although your version may work.
today =
currentDate.getDate()+"/"+currentDate.getMonth()+"/"+currentDate.getYear();

Wrong month, see via FAQ. As an apparent Canadian, you should have
noticed that D/M/Y, though moderately logical, is often
indistinguishable from M/D/Y which your neighbours like.
cookie = sharedObject.getLocal("date");
if (cookie.data.expire == undefined) {
cookie.data.expire =
(currentDate.getDate()+7)+"/"+currentDate.getMonth()+"/"+currentDate.getYear
();

Gives non-existent date if today is in the last 7 days of the month; I
know no reason to expect that to be acceptable. Can give non-existent
month.
cookie.data.today = today;
} else {
sepToday = cookie.data.today.split("/");
sepExpire = cookie.data.expire.split("/");
if (Number(sepToday[0]) >= Number(sepExpire[0]) && Number(sepToday[1]) <=
Number(sepExpire[1])) {
this.stop(); //stay stopped on frame 1
} else {
this.gotoAndPlay(2); //Play movie
}
}

Looks as if it may fail around year-end. See below.
 
J

John G Harris

Dr John Stockton said:
JRS: In article <[email protected]>, dated Sun, 5
Sep 2004 11:38:18, seen in FayeC


Should be new Date() , although your version may work.
<snip>

Both new Date and new Date() are valid and mean the same thing.

John
 
R

Randy Webb

John said:
<snip>

Both new Date and new Date() are valid and mean the same thing.

2 Questions:

1) Is that documented anywhere?
2) How do you pass parameters to new Date() if you don't use the ()?
 
L

Lasse Reichstein Nielsen

Randy Webb said:
2 Questions:

1) Is that documented anywhere?

ECMA 262 v3 section 11.2.
The production is:

<LeftHandSideExpression> -> <NewExpression>
-> new <NewExpression>
-> new <MemberExpression>
-> new <PrimaryExpression>
-> new <Identifier>
-> new Date

The evaluation is according to section 11.2.2. First we evaluate the
identifier "Date", giving an object which has a [[Construct]] method.
Then that method is called providing no arguments.

You can trace <LeftHandSideExpression> back to something that is a
valid right hand side as well :)

It's documented for JScript on MSDN:
<URL:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsoprnew.asp>

It works like this in JavaScript 1.0 in Nescape 2, so it's a good
bet it has worked in most browsers since then.
2) How do you pass parameters to new Date() if you don't use the ()?

How do you pass parameters to "new Date()" when you don't specify any
parameters? :)

Omitting the parentheses means that the constructor is called with
no parameters, just as using parentheses with no arguments inside them.

/L
 
R

Richard Cornford

Randy said:
2 Questions:

1) Is that documented anywhere?

ECMA 262 (3rd edition) section 11.2, particularly the first algorithm in
section 11.2.2 (production == NewExpression: new NewExpression). Where
if the operand of the new operator is evaluated and the internal
GetValue function applied to the result returns an Object with a
[[Construct]] method (so a function object), its [[Construct]] method is
called with no arguments.
2) How do you pass parameters to new Date() if you don't use the ()?

Arguments are only passed to the [[construct]] method in the second
algorithm in section 11.2.2 (production == MemberExpression: new
MemberExpression Arguments).

However, knowing that I can use the - new - operator without any
parenthesise in javascript if arguments are not needed, doesn't
encourage me to do so.

Richard.
 

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,755
Messages
2,569,538
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top