Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Object-Oriented JavaScript Getters and Setters Getters

Peter Retvari
seal-mask
.a{fill-rule:evenodd;}techdegree
Peter Retvari
Full Stack JavaScript Techdegree Student 8,392 Points

Question regarding new Date ()

Dears,

This new Date () is a little bit confusing for me. We learned in the previous video, that using:

 const Eddie = new Pet ('parrot', 2, 'hawai parrot');

means creating an object, called 'Eddie' with the Pet class, invoking the constructor method. It was pretty handy when we wanted to create several objects for the pets with similar properties.

On the other hand, we used the same method to get the actual day with this:

 const today = new Date ();

My question is: 1) How we got the actual day with this? We just created a today object using the class Date's constructor method. What's going on under the hood? I think that with this new Date () we are accessing the Date's properties (like getHours, getMinutes...) and we can use them. But how can I get a value from it? The Date class looks like this?

class Date {

constructor (

this.getHours = 'calculate the hours of the day somehow'

)

}

1 Answer

Javascript has many design patterns for creating objects, there is a good book by addi osmani at Google which goes into a lot of detail https://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript. Some classes have an api with methods that let you interact with the new object you create, as you mentioned in your comment about the date object you created above. Other functionality has purposely been hidden from you so you dont have to worry about it, this type of abstraction is really useful in programming