CommonJS Modules - Export a function that returns a function with arguments

This rendr - sessions has a middleware module ...

module.exports = function incrementCounter() {
  return function incrementCounter(req, res, next) {
    var app = req.rendrApp
      , count = app.get('session').count || 0;
    req.updateSession('count', count + 1);
    next();
  };
};

Can you not achieve the same with the following?

module.exports = function incrementCounter(req, res, next) {
  var app = req.rendrAp
  , count = app.get('session').count || 0;
  req.updateSession('count', count + 1);
  next();
};

My question is: why are you exporting a function that returns a function with arguments? Is there any benefit to the first that I don't know about?

+1
source share
1 answer

rendr uses Express type middleware.

Express . , .

, , .

, , factory, . , .

+1

Source: https://habr.com/ru/post/1665002/


All Articles