Loading video player…

Objects, this and Classes (Overview)

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:

Language: Text
[ '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 this refers 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.

Download

Course Slides (.pdf)

714.3 KB
Download

Sample Code (.zip)

11.3 KB

00:00 Welcome to Objects, this and Classes. So far, your objects hold data, and separate functions work on them. In this course, they get methods that work on that data, and they guard it.

00:15 For a first taste, here’s Mei’s finished houseplant tracker. Her four plants are objects made from one Plant class, on a shelf. Run it, and the shelf lists the plants due for water today.

00:29 A plain record would take a negative interval. These plants refuse it.

00:35 Mei’s tracker starts with plain records and separate functions. Along the way, one line that looks right loses track of the shelf. You’ll find out why, and fix it in the project.

00:49 By the end, you’ll be able to model things that hold data and behavior with classes, protect their data with private fields and accessors, and predict what this refers to in any call.

01:01 Accessors are getters and setters, code that runs when a property is read or set, like Moss’s check. The keyword this is set by the call: call a method on an object, and this names that object.

01:15 Then comes Mei’s tracker.

01:19 You should already know functions, arrays and objects, arrow functions as callbacks, modules and thrown errors. If you’re new here, Mei’s story starts in this course.

01:30 You’ll need a terminal, any editor, and a current Node LTS. The examples ran on Node 26.

01:39 Lessons are text or short video, and you type along in Node. The first four sections each end with a browser coding exercise, checked by tests. Then you build Mei’s tracker, explain it to the AI mentor in a chat, and take a quiz.

01:55 First up is Give Objects Their Own Methods.

Become a Member to join the conversation.