3 ms·
Two useful things YUI provides around this (and I'm sure other libraries have similar), are: 1. Y.rbind, which does the same thing as bind, but appends the arg
by natecavanaugh 13y ago
Two useful things YUI provides around this (and I'm sure other libraries have similar), are:
1. Y.rbind, which does the same thing as bind, but appends the arguments (to me, this is more useful, as often, I'm binding a single function thats defined somewhere that expects at least the event obj as the first arg, but may be able to handle optional arguments that I could bind to an instance of that fn)
2. The ability to create a bound function using only the name of the function and the object it exists on.
Using something like Y.bind('myFn', obj);, the function that will be executed will be looked up at runtime rather than at the time the bound fn is created.
This is extremely useful for cases where you may be using AOP or monkey patching to displace a function before it's executed. It also allows you to bind a function before it exists.
Passing in a reference to the function at bind time protects against cases like that, but I find it far more useful than just binding the reference.