One blueprint, many objects

INPUT · Slides

Objects, one more time

01 / 04

Before classes, objects

The class you will learn in this chapter is a tool for turning objects out in quantity.

So let us bring the object, the thing underneath it, back to mind first. No new grammar. This lesson is for getting your hands moving and the feel back.

02 / 04

Held as name-and-value pairs

An object is name: value pairs lined up inside { }, separated by ,. To take one out you write .name.

Each one of those name-and-value pairs was a property.

const card = { title: "Star Map", level: 3 };console.log(card.title);console.log(card.level);

Result

Star Map
3

03 / 04

It gets painful as the same shape piles up

Making several objects of the same shape means writing out the { } by hand every time.

Mistype a property name in just one place and it is hard to notice, and wanting to add a field later means fixing every one of them.

That pain of "I want to turn out the same shape in quantity" is what leads to the class in the next lesson.

const a = { title: "Star Map", level: 3 };const b = { title: "Moon Flute", level: 5 };console.log(a.title);console.log(b.title);

Result

Star Map
Moon Flute

04 / 04

The tools here are ones you have

Everything in this round of exercises is a tool you have already learned.

  • objects and properties
  • arrays and for
  • if for branching
  • functions and return

Write some and let it come back to you.