Search⌘ K

Serialization and Data Management in Model Code

Explore how to implement serialization and manage data in JavaScript model code that includes single and multi-valued enumeration attributes. Learn to handle array copying, equality testing, and improve code readability with custom methods while updating model data. This lesson helps you understand data management in building front-end apps without frameworks.

Write a serialization function

The object serialization function toString() now needs to include the values of enumeration attributes.

Javascript (babel-node)
class Book {
...
toString() {
return "Book{ ISBN:" + this.isbn + ", title:" + this.title +
", originalLanguage:" + this.originalLanguage +
", otherAvailableLanguages:" +
this.otherAvailableLanguages.toString() +
", category:" + this.category +
", publicationForms:" +
this.publicationForms.toString() + "}";
}
...
}

Notice that for multi-valued enumeration attributes, we call the toString() function predefined for JS arrays.

Data

...