Code the Model Classes

Let’s learn how to code the model classes.

The JS class model can be directly coded to get the code of the model classes of our JS front-end application.

Summary

  1. Code the enumeration type BookCategoryEL to be used as the range of the category attribute with the help of the meta-class Enumeration.
  2. Code the model class Book in the form of a JS class definition with get and set methods as well as static check functions.

These steps are discussed in more detail in the following sections.

Code the enumeration type BookCategoryEL

The enumeration type BookCategoryEL is coded with the help of our library meta-class Enumeration at the beginning of the Book.js model class file in the following way:

BookCategoryEL = new Enumeration([ "Textbook", "Biography"]);

Code the model class Book

We code the model class Book in the form of an ES2015 class definition where the category attribute as well as the segment attributes subjectArea and about are optional, with getters, setters, and static check functions for all properties.

Get hands-on with 1200+ tech skills courses.