Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Days of the Week

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #157315
    Gary Pickles
    Participant

    My first bit of jQuery, which finds the day of the week and highlights the day in an UL.

    My Question is can these two lines be combined?

    var day = new Date(); var weekday = day.getDay()
    
    #157316
    Gary Pickles
    Participant

    I made a pen

    [Day of the Week Pen…](

    See the Pen IczhD by Gary Pickles (@Garypickles) on CodePen

    “Day of the week Pen”)

    #157326
    __
    Participant

    My Question is can these two lines be combined?

    very simply:

    var weekday = new Date().getDay();
    

    This is called “method chaining.” Since functions are first-class (and, since functions are objects) in javascript, this will work any time the function/method on the left (e.g., Date) returns an object that has the method/property on the right (e.g., getDay).

    #157328
    Gary Pickles
    Participant

    Thank you :)

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.