O'Reilly logo

Learning Underscore.js by Alex Pop

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Migrating to a functional programming style

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required