We will revisit the examples in the folder oop-underscore
from the source code for this chapter and adapt them to use standalone functions instead of object methods:
We will keep the classes as simple data structures and we will even preserve the inheritance
We will move all the functionality around validation and any object methods outside the original classes
Because we want to preserve the existing functionality, we will leave the test specifications unchanged together with the code that displays the example output. First of all, we will move the validation logic into a separate validations.js
file. The object constructor functions for Contact
and Client
are validating the argument's length and we will move this functionality into a new function:
validateArgsLength: function(argsLength, argsArray) { if (argsArray.length != argsLength) { throw { name: "ArgumentsException", message: "The arguments length is incorrect." }; ...