From e6bf995f2dae8bd12da6c2f470b0bee5bc250573 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Mon, 3 Aug 2015 15:28:53 +0500 Subject: [PATCH] lodash: added _.methodOf() method --- lodash/lodash-tests.ts | 12 ++++++++++++ lodash/lodash.d.ts | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index afdc3c0e8d..4c37829410 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1435,6 +1435,18 @@ result = (_.method(['a', 'b'], 1, 2))(TestMethodObject); result = (_('a.b').method(1, 2).value())(TestMethodObject); result = (_(['a', 'b']).method(1, 2).value())(TestMethodObject); +// _.methodOf +class TestMethodOf { + a = [ + (a1: number, a2: number) => a1 + a2 + ]; +} +var TestMethodOfObject = new TestMethodOf(); +result = (_.methodOf(TestMethodOfObject, 1, 2))('a[0]'); +result = (_.methodOf(TestMethodOfObject, 1, 2))(['a', '0']); +result = (_(TestMethodOfObject).methodOf(1, 2).value())('a[0]'); +result = (_(TestMethodOfObject).methodOf(1, 2).value())(['a', '0']); + result = _.VERSION; result = <_.Support>_.support; result = <_.TemplateSettings>_.templateSettings; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index c75ca9979f..b74e013c6e 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -6987,6 +6987,25 @@ declare module _ { method(...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(object: Object, ...args: any[]): (path: string | any[]) => TResult; + } + + interface LoDashObjectWrapper { + /** + * @see _.methodOf + */ + methodOf(...args: any[]): LoDashObjectWrapper<(path: string | any[]) => TResult>; + } + //_.mixin interface LoDashStatic { /**