Search⌘ K
AI Features

Model Code: Property Checks and Property Setters

Explore how to code property check functions as class-level methods and setters as instance-level methods to validate mandatory values and uniqueness constraints. Understand the importance of datatype conversion within model code to maintain data integrity and error handling during property assignment in your JavaScript front-end application.

Code the property checks

We code the property check functions in the form of class-level (“static”) methods. In JavaScript, this means we define them as method slots of the constructor, as in Book.checkIsbn. Recall that a constructor is a JavaScript object, since in JS, functions are objects, and as an object, it can have slots.

Take care that all constraints of a property as specified in the class model are properly coded in its check function. This concerns, in particular, the mandatory value and uniqueness constraints implied by the standard identifier declaration (with {id}), as well as the mandatory value constraints for all properties ...