title: Chain functions in JavaScript
body: <p>Is there a way to chain functions in JavaScript so when last function in chain is called we take into consideration all function in chain that was specified.
  Basically what I am trying to do is the same thing <a href="https://github.com/express-validator/express-validator" rel="nofollow noreferrer">express-validator</a> 
  does:
  Something like this:</p>
  
  <pre><code>check('password').passwordValidator().optional();
  </code></pre>
  
  <p>I want to be able to call </p>
  
  <pre><code>check('password').passwordValidator();
  </code></pre>
  
  <p>and </p>
  
  <pre><code>check('password').passwordValidator().optional();
  </code></pre>