Web Analytics Made Easy -
StatCounter Newbie. basic misundersanding of language structure - CodingForum

Announcement

Collapse
No announcement yet.

Newbie. basic misundersanding of language structure

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie. basic misundersanding of language structure

    Code:
       exp = new Date()
       oneYearFromNow = exp.getTime() + (365*24*60*60*1000)
       exp.setTime(oneYearFromNow)
       gmt = exp.toGMTString()
    In this copied example, the third line is not an assignment yet sets a property of EXP. Why do we sometimes require not to have the =?

    Clearly this is a daft question the answer to which should be on about page 1 of the book. Yet RTFM has not given me the answer. Sorry, everyone.

    Next question; how can I combine 4 lines to 1 to set the variable GMT? Or can't I?

  • #2
    Hi,

    'setTime(...)' is a built in javascript function that, as its name says, sets a value (the time) for the variable that preceeds the dot (exp). Somewhere within the built in function there is an "=" assignment operator. [Many, if not all of the built in functions, do assignments.]

    I just woke up and haven't had my mugs of espresso yet, so in re to your last question: In general, you can combine lines by placing functions within functions.

    For example, you should be able to combine lines 2 & 3, as in:

    exp.setTime( (exp.getTime() + (365*24*60*60*1000) )

    but I've never tried to combine lines simply for the sake of doing so. What would be the point? It would only make the code the hard to follow and later debug.



    Vinny
    Where the world once stood
    the blades of grass
    cut me still

    Comment


    • #3
      Thanks for your help, Vinnie

      Originally posted by Vincent Puglia
      'setTime(...)' is a built in javascript function that, as its name says, sets a value (the time) for the variable that preceeds the dot (exp). Somewhere within the built in function there is an "=" assignment operator. [Many, if not all of the built in functions, do assignments.]
      Hmm, but not all; it's just an RTFM problem to work out which do or don't? Is there a general rule? For instance, I don't think toGMTString does.
      but I've never tried to combine lines simply for the sake of doing so. What would be the point? It would only make the code the hard to follow and later debug.
      Quite so; I'm very new and want to learn what I can and can't actually do in this (big!?) language; real-life style is of course KISS.

      Comment


      • #4
        Hi,

        You seem to be delving too deeply. Javascript is a relatively simple c-like language. If you pick up and read O'Reilly Publisher's Javascript: a Definitive Guide, many of your questions will be answered.

        General rule is: when in doubt, see how other people use a function.

        Vinny
        Where the world once stood
        the blades of grass
        cut me still

        Comment

        Working...
        X