May 2022
Beginner
304 pages
6h 49m
English
In Section 4.4, we learned how to make plain objects, which we used as simple associative arrays of key–value pairs. In this chapter, we’ll make more general versions of JavaScript objects, ones that have both properties (data) and methods (functions) attached to them.
There is a dizzying variety of ways to define objects in JavaScript, but we’ll focus on one of the most classic ways, which is to use functions (Chapter 5). The result will be an object constructor function that can be used to create (or instantiate) a new object (called an instance) using the new syntax we first saw in Section 4.2.
We’ll start by defining a Phrase object. Eventually, we’ll use Phrase to represent a phrase ...
Read now
Unlock full access