Search⌘ K

Single-Valued Reference Properties

Explore how to manage single-valued reference properties in JavaScript class models by using ES2015 parameter destructuring. Understand how to flexibly assign object or ID references within constructors and handle type checking in property setters.

We'll cover the following...

Implementation

When coding a class, the ES2015 feature of function parameter destructuring allows us to use a single constructor parameter as a record with a simplified syntax for defining its fields. We make use of this new feature by obtaining a simplified class definition syntax, as shown in the following example:

Javascript (babel-node)
class Book {
constructor({ isbn, title, year, ...}) {
this.isbn = isbn;
this.title = title;
this.year = year;
...
}
...
}
...