documentcloud/underscore — pull request #476 by alexindigo (2012-02-16 07:24:00+00:00)
Title: Added two function methods _.curry and _.attach (+ tests)

* ```_.curry``` – Curries (burns in) arguments to a function, without forcing new context (inspired by prototypejs).

Difference between ```_.curry``` and ```_.bind```: http://jsfiddle.net/CqG7n/

* ```_.attach``` – Attaches new properties to the context of the call, in other words it extends passed object(s) with 'this' and makes it context.

To illustrate my use case I modified example from flatiron/director

```
// api.js
function helloWorld(route) {
this.res.writeHead(200, { 'Content-Type': 'text/plain' })
this.res.end('hello world from (' + route + ')');
}

// router.js
var router = new director.http.Router({
'/hello': {
get: helloWorld
}
});
```

And I want to provided to my handlers stuff like db-resourse, application home path, etc.,
without expanding list of function parameters, but rather adding to the context.

Using ```_.attach```

```
// api.js
function helloWorld(route) {
fs.readFile(this.apphome+'/etc/passwd', function (err, data) {
this.res.writeHead(200, { 'Content-Type': 'text/plain' })
this.res.end(data);
});
}

// router.js
var apphome = '/var/www';
var router = new director.http.Router({
'/hello': {
get: _.attach(helloWorld, {apphome: apphome})
}
});
```