Validation.js - why not use prototypes?

Is there a reason why isCompanyEmail isn’t a prototype function? It looks to me like it’s a computed property of Validation, is that correct?

Great question!

isCompanyEmail is actually not a computed property, but I can see how it might seem that way. It’s just a plain function that happens to be a property of the Validation object. It makes no references to this, so it doesn’t really need to be a prototype function.

For CoffeeRun, Validation is only a “library” of functions, as opposed to a new type that will be instantiated via new.

Constructors (custom types) are what you want for separating data (instance variables) from actions (prototype methods). In the case of validating user input for CoffeeRun, we don’t need anything that extensive, nor do we need multiple instances. Instead, we use an object literal to organize our validation functions.

A good example of using an object-for-organizing-related-functionality is the built-in Math object. Contrast this with the Date constructor, which is a function for instantiating Date objects.

Does that help clarify things?

Thanks, that does make sense. I’ve just been struggling with the Silver challenge at the end of chapter 13 - Validating Against the Remote Server - so I was going back and making sure I understood how everything was working. Perhaps I’ll post about that struggle in the Ch. 13 section!