max-mapper / callback-hell

information about async javascript programming
http://callbackhell.com
847 stars 100 forks source link

Curring and closures #13

Open jfromaniello opened 11 years ago

jfromaniello commented 11 years ago

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'));