documentcloud/underscore — pull request #858 by jcromartie (2012-11-13 16:05:17+00:00)
Title: Add _.toFunction to convert objects to functions of their keys

_.toFunction returns a function which represents the object as a
function of its keys. For example, it turns an array into a function
of its indices, so:

var f = _.toFunction(["zero", "one", "two"]);
f(0); // returns "zero"

This is useful in combination with collection methods, like map or
filter, so that objects can be easily converted to map or filter
arguments, like so:

// returns a subset of someArray with only the values at 3 5 and 6
var subset = _.map([3, 5, 6], _.toFunction(someArray));