Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Object-Oriented JavaScript!
You have completed Object-Oriented JavaScript!
Preview
Create properties with dynamic values using getters in JavaScript.
Resources
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
In JavaScript, there are two special
methods called getters and setters.
0:00
These methods allow us to create and
retrieve or
0:00
update an object's
properties respectively.
0:03
You learned previously how to access or
0:06
update an object's properties
using dot and bracket notation.
0:08
So why do we need methods
that do the same thing?
0:11
I promise that the answer is not
to needlessly complicate things.
0:14
The idea behind getter and
setter methods is to increase flexibility.
0:18
With getter and setter methods,
you have the option to include logic when
0:21
retrieving or setting the value of
a property while still enjoying the simple
0:25
syntax of accessing and
setting these properties directly.
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up