...

/

Model Code: Property Checks and Property Setters

Model Code: Property Checks and Property Setters

Let’s learn how to code the property checks and property setters for the model.

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 ...