mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
added _.bindKey definition
This commit is contained in:
+17
-3
@@ -393,11 +393,11 @@ _.forEach(saves, function(type) {
|
||||
asyncSave({ 'type': type, 'complete': done });
|
||||
});
|
||||
|
||||
var func = function (greeting) { return greeting + ' ' + this.name };
|
||||
var funcBind = function (greeting) { return greeting + ' ' + this.name };
|
||||
// need a second var otherwise typescript thinks func signature is the above func type,
|
||||
// instead of the newly returned _bind => func type.
|
||||
var func2 = _.bind(func, { 'name': 'moe' }, 'hi');
|
||||
func2();
|
||||
var funcBind2 = _.bind(funcBind, { 'name': 'moe' }, 'hi');
|
||||
funcBind2();
|
||||
|
||||
var view = {
|
||||
'label': 'docs',
|
||||
@@ -407,7 +407,21 @@ var view = {
|
||||
_.bindAll(view);
|
||||
jQuery('#docs').on('click', view.onClick);
|
||||
|
||||
var objectBindKey = {
|
||||
'name': 'moe',
|
||||
'greet': function(greeting) {
|
||||
return greeting + ' ' + this.name;
|
||||
}
|
||||
};
|
||||
|
||||
var funcBindKey = _.bindKey(object, 'greet', 'hi');
|
||||
funcBindKey();
|
||||
|
||||
objectBindKey.greet = function(greeting) {
|
||||
return greeting + ', ' + this.name + '!';
|
||||
};
|
||||
|
||||
funcBindKey();
|
||||
|
||||
|
||||
|
||||
|
||||
Vendored
+14
-1
@@ -1731,7 +1731,20 @@ declare module _ {
|
||||
object: any,
|
||||
...methodNames: string[]): any;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a function that, when called, invokes the method at object[key] and prepends any
|
||||
* additional bindKey arguments to those provided to the bound function. This method differs
|
||||
* from _.bind by allowing bound functions to reference methods that will be redefined or don't
|
||||
* yet exist. See http://michaux.ca/articles/lazy-function-definition-pattern.
|
||||
* @param object The object the method belongs to.
|
||||
* @param key The key of the method.
|
||||
* @param args Arguments to be partially applied.
|
||||
* @return The new bound function.
|
||||
**/
|
||||
export function bindKey(
|
||||
object: any,
|
||||
key: string,
|
||||
...args: any[]): Function;
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user