documentcloud/underscore — Issue #412: enhancement request for .bindAll and .functions
Author: kof
Created: 2011-12-21 19:58:48+00:00
State: open

Would you accept a pull request or would you like to implement the following idea:

My current usecase: in backbone views we often use .bindAll for event handlers. Currently there are 2 options, bind to all functions of the instance or to name functions explicitly.

My idea is to pass a second argument to bindAll, which is a regexp for functions selection.

At this way I could write `_.bindAll(this, /^handler/)`

I am using my personal convention and all event handlers a prefixed by 'handler', so all handlers will now have the conext of my view instance.

.bindAll and .functions have to be patched, the side effect .functions will also accept 2. param and one can filter the functions.

What do you think about it?

Best,
Oleg