So far, your objects hold data, and separate functions work on them. In this course, your objects get methods that work on that data, and they guard it. You’ll build that up by helping Mei with her houseplant care tracker.
In the finished tracker, Mei’s four plants are objects made from one Plant class, on a shelf. Run it, and the shelf lists the plants due for water today. A plain record would take a negative watering interval, but these plants refuse it:
[ 'Water Goldie', 'Water Lily' ]
RangeError: Negative interval: -7
Mei’s tracker starts as plain records and separate functions. Along the way, one line that looks right loses track of the shelf and stops with an error. You’ll find out why, and fix it in the project.
What You’ll Learn
By the end of this course, you’ll be able to:
- Model things that hold data and behavior with classes.
- Protect their data with private fields and accessors.
- Predict what
thisrefers to in any call.
Accessors are getters and setters, code that runs when a property is read or set, like the check that stopped Moss. The keyword this is set by the call: call a method on an object, and this names that object. Then you’ll put it all together in Mei’s tracker.
Before You Start
You should already know functions, arrays and objects, arrow functions as callbacks, modules, and thrown errors. If this is your first course here, Mei’s story starts in this course.
You’ll need a terminal, any editor, and a current LTS version of Node. The examples in this course ran on Node 26.
How the Course Works
Lessons are text or short video, and you type along in the Node REPL and in your own scripts. Each of the first four sections ends with a coding exercise that runs in your browser and is checked by tests. Then you’ll build Mei’s tracker as a project, explain it to the course’s AI mentor in a chat, and take a quiz.
First up is a text lesson, Give Objects Their Own Methods.