Weird Code: Check My Reading of It

Discussion in 'Javascript' started by Gene Wirchenko, Dec 9, 2011.

  1. 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
     
    Gene Wirchenko, Dec 9, 2011
    #1
    1. Advertising

  2. Gene Wirchenko

    David Mark Guest

    On Dec 8, 11:46 pm, Gene Wirchenko <> wrote:
    > 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.

    >
    >      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
     
    David Mark, Dec 9, 2011
    #2
    1. Advertising

  3. On 12/09/2011 12:34 AM, David Mark wrote:
    > On Dec 8, 11:46 pm, Gene Wirchenko<> wrote:
    >> 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).

    >>
    >> 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

    >


    --
    Norman
    Registered Linux user #461062
    AMD64X2 6400+ Ubuntu 10.04 64bit
     
    Norman Peelman, Dec 9, 2011
    #3
  4. On Fri, 09 Dec 2011 06:55:18 -0500, Norman Peelman
    <> wrote:

    >On 12/09/2011 12:34 AM, David Mark wrote:
    >> On Dec 8, 11:46 pm, Gene Wirchenko<> wrote:
    >>> 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.

    >> 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).


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

    [snip]

    Sincerely,

    Gene Wirchenko

    ..
     
    Gene Wirchenko, Dec 9, 2011
    #4
  5. Gene Wirchenko

    David Mark Guest

    On Dec 9, 6:55 am, Norman Peelman <> wrote:
    > On 12/09/2011 12:34 AM, David Mark wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > On Dec 8, 11:46 pm, Gene Wirchenko<>  wrote:
    > >> 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. ;)
     
    David Mark, Dec 9, 2011
    #5
  6. In comp.lang.javascript message <k243e7ltslnc4op0hd6api696jep2qja0j@4ax.
    com>, Thu, 8 Dec 2011 20:46:41, Gene Wirchenko <> posted:

    >***** 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]

    --
    (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
    Website <http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
    PAS EXE etc. : <http://www.merlyn.demon.co.uk/programs/> - see in 00index.htm
    Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
     
    Dr J R Stockton, Dec 10, 2011
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dorayme
    Replies:
    1
    Views:
    630
    richard
    Jan 21, 2011
  2. richard
    Replies:
    0
    Views:
    592
    richard
    Jan 21, 2011
  3. richard
    Replies:
    0
    Views:
    621
    richard
    Jan 21, 2011
  4. Beauregard T. Shagnasty

    Re: A Weird Appearance for a Weird Site

    Beauregard T. Shagnasty, Jan 21, 2011, in forum: HTML
    Replies:
    1
    Views:
    446
    Captain Paralytic
    Jan 21, 2011
  5. David Segall
    Replies:
    0
    Views:
    640
    David Segall
    Jan 22, 2011
Loading...

Share This Page