callback-hell icon indicating copy to clipboard operation
callback-hell copied to clipboard

Curring and closures

Open jfromaniello opened this issue 13 years ago • 0 comments

An example could be:

app.get('something', function (req, res) {
  res.render('view1');
});

app.get('other', function (req, res) {
  res.render('view1');
});

Refactor to:

function respondWithView (viewName) {
 return function ( req, res ) {
   res.render(viewName);
 };
}

app.get('something', respondWithView('view1'));

app.get('other', respondWithView('view2'));

jfromaniello avatar Dec 23 '12 17:12 jfromaniello