lodash: added _.methodOf() method

This commit is contained in:
Ilya Mochalov
2015-08-03 15:28:53 +05:00
parent 287cb2e1b1
commit e6bf995f2d
2 changed files with 31 additions and 0 deletions

View File

@@ -1435,6 +1435,18 @@ result = <number>(_.method<number>(['a', 'b'], 1, 2))(TestMethodObject);
result = <number>(_('a.b').method<number>(1, 2).value())(TestMethodObject);
result = <number>(_(['a', 'b']).method<number>(1, 2).value())(TestMethodObject);
// _.methodOf
class TestMethodOf {
a = [
(a1: number, a2: number) => a1 + a2
];
}
var TestMethodOfObject = new TestMethodOf();
result = <number>(_.methodOf<number>(TestMethodOfObject, 1, 2))('a[0]');
result = <number>(_.methodOf<number>(TestMethodOfObject, 1, 2))(['a', '0']);
result = <number>(_(TestMethodOfObject).methodOf<number>(1, 2).value())('a[0]');
result = <number>(_(TestMethodOfObject).methodOf<number>(1, 2).value())(['a', '0']);
result = <string>_.VERSION;
result = <_.Support>_.support;
result = <_.TemplateSettings>_.templateSettings;

19
lodash/lodash.d.ts vendored
View File

@@ -6987,6 +6987,25 @@ declare module _ {
method<TResult>(...args: any[]): LoDashWrapper<(object: any) => TResult>;
}
//_.methodOf
interface LoDashStatic {
/**
* The opposite of _.method; this method creates a function that invokes the method at a given path on object.
* Any additional arguments are provided to the invoked method.
* @param object The object to query.
* @param args The arguments to invoke the method with.
* @return Returns the new function.
*/
methodOf<TResult>(object: Object, ...args: any[]): (path: string | any[]) => TResult;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.methodOf
*/
methodOf<TResult>(...args: any[]): LoDashObjectWrapper<(path: string | any[]) => TResult>;
}
//_.mixin
interface LoDashStatic {
/**