Weird Code: Check My Reading of It

G

Gene Wirchenko

Dear JavaScripters:

The text I am following has a oddball piece of code. Please
check that I am reading it right.

***** Start of Oddball Code *****
function writeDocument(n,s) {
var doc=parent.frames[1].frames[n].location = s
}
***** End of Oddball Code *****

As I read this, the location for a frame will be set to s. doc,
a local variable, will be set to s as well. But this is all there is
to the function, and therefore, the
var doc=
part of the body serves no useful purpose.

Am I correct in my reading?

Sometimes, I think that errors like this in a text are horrible;
other times, I think it is good exercise. I am undecided here. (I
did not know about JavaScript's multiple assignment, so I suppose that
I have learned something.)

Sincerely,

Gene Wirchenko
 
D

David Mark

Dear JavaScripters:

     The text I am following has a oddball piece of code.  Please
check that I am reading it right.

***** Start of Oddball Code *****
function writeDocument(n,s) {
 var doc=parent.frames[1].frames[n].location = s}

***** End of Oddball Code *****

     As I read this, the location for a frame will be set to s.  doc,
a local variable, will be set to s as well.  But this is all there is
to the function, and therefore, the
          var doc=
part of the body serves no useful purpose.

Right. Goes right out of scope.

And why they are trying to set the location property is anyone's
guess.
 
N

Norman Peelman

Dear JavaScripters:

The text I am following has a oddball piece of code. Please
check that I am reading it right.

***** Start of Oddball Code *****
function writeDocument(n,s) {
var doc=parent.frames[1].frames[n].location = s}

***** End of Oddball Code *****

As I read this, the location for a frame will be set to s. doc,
a local variable, will be set to s as well. But this is all there is
to the function, and therefore, the
var doc=
part of the body serves no useful purpose.

Right. Goes right out of scope.

Is there an attempt to use 'doc' (this one that has just been
assigned parent.frames[1].frames[n].location) anywhere else in the code?
And why they are trying to set the location property is anyone's
guess.

I assume to load the new location into the desired frame(n).
 
G

Gene Wirchenko

Dear JavaScripters:

The text I am following has a oddball piece of code. Please
check that I am reading it right.

***** Start of Oddball Code *****
function writeDocument(n,s) {
var doc=parent.frames[1].frames[n].location = s}

***** End of Oddball Code *****

As I read this, the location for a frame will be set to s. doc,
a local variable, will be set to s as well. But this is all there is
to the function, and therefore, the
var doc=
part of the body serves no useful purpose.

Right. Goes right out of scope.

Thank you.
Is there an attempt to use 'doc' (this one that has just been
assigned parent.frames[1].frames[n].location) anywhere else in the code?

I have not entered the code so I can not search it so easily, but
in my eyeball scans of the code, I have seen no other use of doc.
I assume to load the new location into the desired frame(n).

Exactly. It is a simple catalog, and the displaying is of a
picture and the product name.

[snip]

Sincerely,

Gene Wirchenko

..
 
D

David Mark

Dear JavaScripters:
      The text I am following has a oddball piece of code.  Please
check that I am reading it right.
***** Start of Oddball Code *****
function writeDocument(n,s) {
  var doc=parent.frames[1].frames[n].location = s}
***** End of Oddball Code *****
      As I read this, the location for a frame will be set to s. doc,
a local variable, will be set to s as well.  But this is all there is
to the function, and therefore, the
           var doc=
part of the body serves no useful purpose.
Right. Goes right out of scope.

   Is there an attempt to use 'doc' (this one that has just been
assigned parent.frames[1].frames[n].location) anywhere else in the code?
And why they are trying to set the location property is anyone's
guess.

   I assume to load the new location into the desired frame(n).

But that's the location.href property. ;)
 
D

Dr J R Stockton

In comp.lang.javascript message <k243e7ltslnc4op0hd6api696jep2qja0j@4ax.
***** Start of Oddball Code *****
function writeDocument(n,s) {
var doc=parent.frames[1].frames[n].location = s
}
***** End of Oddball Code *****

From the function line, I would half-expect that to have been intended
to write the general HTML string s into the specified frame, in which
case there is a missing (.innerHTML || .somethingElse).
As I read this, the location for a frame will be set to s. doc,
a local variable, will be set to s as well. But this is all there is
to the function, and therefore, the
var doc=
part of the body serves no useful purpose.

Yes. I would have used location.href.
(I
did not know about JavaScript's multiple assignment

Be careful with it.

X = Y = 3 ; Y++ ; Z = [+X, +Y] // [3, 4]
X = Y = new Date() ; Y.setTime(3456) ; Z = [+X, +Y] // [3456, 3456]
 

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

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top