title: How to pass parameters to function without calling function?
body: <p>I'm trying to find a way to get a function requiring a parameter without actually calling the function.</p>
  
  <p>Current broken code example:</p>
  
  <pre><code>const _validations = {
    userID: (req) =&gt; check('userID').isString().isUUID('4').run(req),
  };
  
  async function (req, res, next) {
    const allReqFields = { ...req.body, ...req.params, ...req.query };
  
    const fieldsFound = [];
    for (let key of Object.keys(allReqFields)) {
      if (_.has(_validations, key)) {
        fieldsFound.push(_validations[key](req));
      }
    }
  
    await Promise.all(fieldsFound);
  
    return next();
  },
    function (req, res, next) {
      const errors = validationResult(req);
  
      if (errors.isEmpty()) {
  //ALWAYS HITS HERE
        return next();
      }else{}
  }
  </code></pre>
  
  <p>Code example that works but I don't want:</p>
  
  <pre><code>const _validations = {
    userID: (req) =&gt; check('userID').isString().isUUID('4').run(req),
  };
  
  async function (req, res, next) {
    const allReqFields = { ...req.body, ...req.params, ...req.query };
  
    for (let key of Object.keys(allReqFields)) {
      if (_.has(_validations, key)) {
        await _validations[key](req);
      }
    }
  
  
    return next();
  },
    function (req, res, next) {
      const errors = validationResult(req);
  
      if (errors.isEmpty()) {
  //Correctly hits here
        return next();
      }else{
  //Correctly hits here
      }
  }
  </code></pre>
  
  <p>For some context:</p>
  
  <p>The function <code>(req) =&gt; check('userID').isString().isUUID('4').run(req),</code> returns a promise.</p>
  
  <p>There are going to be more keys/values inside the <code>_validations</code> object.</p>
  
  <p>Every function inside of <code>_validations</code> will require <code>req</code> to be passed to it.</p>
  
  <p>The end goal is to run all those async functions while having req passed to them.</p>
  
  <p><strong>The issue I'm having now is that <code>fieldsFound.push(_validations[key](req));</code> is pushing a promise and not the function for me to call later. Which means that <code>fieldsFound</code> is an array of unresolved promises</strong></p>
  
  <p>Any ideas? Thanks!</p>