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

  2. Gene Wirchenko

    David Mark Guest

    Right. Goes right out of scope.

    And why they are trying to set the location property is anyone's
    guess.
     
    David Mark, Dec 9, 2011
    #2
    1. Advertisements

  3. 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 assume to load the new location into the desired frame(n).
     
    Norman Peelman, Dec 9, 2011
    #3
  4. Thank you.
    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.
    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

    But that's the location.href property. ;)
     
    David Mark, Dec 9, 2011
    #5
  6. In comp.lang.javascript message <k243e7ltslnc4op0hd6api696jep2qja0j@4ax.
    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).
    Yes. I would have used location.href.
    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]
     
    Dr J R Stockton, Dec 10, 2011
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.