DEV Community

Discussion on: Method Chaining in JavaScript

Collapse
 
nedsoft profile image
Chinedu Orie

I think it depends on what you want to achieve, you could split it to multiple classes and have them inherit each other depending on what you want to achieve

Collapse
 
shreyansh_zazz profile image
Shreyansh Zazz

I have a Validator class which is nothing but the base class having methods like validate(), and some root properties which will be needed for processing. Then we will have different classes like Type Validator which will have methods validate types like isString, isInt, etc. Then we will have classes like DB Validator which will have methods like isDuplicateUser, etc.

In order to use this Validator I will import and call chained methods like Validator().isString().isDuplicate().validate("username") @nedsoft