3 ms·
> Another way is jQuery.proxy() Or the numerous ``bind`` functions and methods (which do the same thing). In fact, ES5's Function prototype even grew a ``bind
by masklinn 16y ago
> Another way is jQuery.proxy()
Or the numerous ``bind`` functions and methods (which do the same thing).
In fact, ES5's Function prototype even grew a ``bind`` method[0], which is used to partially apply a function (both to bind it to a ``this`` and to bind it to an arbitrary number of arguments).
Some libraries (e.g. underscore) also have a shortcut to bind all methods of an object (or only a subset of those)[1], handy when using methods as event or deferred callbacks
[0] https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind https://developer.mozilla.org/en/JavaScript/Reference/Global...
[1] http://documentcloud.github.com/underscore/#bindAll http://documentcloud.github.com/underscore/#bindAll