From 2fd84867f3c99c28a26d962eeb98b48fcef317ff Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Sun, 20 Oct 2013 20:10:51 -0400 Subject: [PATCH] added _.times definition --- lodash/lodash-tests.ts | 9 +++++++++ lodash/lodash.d.ts | 27 +++++++++++++++------------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index cf7938724..60c960f95 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -760,6 +760,15 @@ result = <_.TemplateExecutor>_.template('hello <%= name %>', null, { 'sourceURL' result = <_.TemplateExecutor>_.template('hi <%= data.name %>!', null, { 'variable': 'data' }); result = (<_.TemplateExecutor>result).source; +function Mage() { + this.castSpell = (n:number) => n; + this.cast = (n: number) => n; +}; +var mage = new Mage(); +result = _.times(3, _.partial(_.random, 1, 6)); +result = _.times(3, function(n: number) { mage.castSpell(n); }); +result = _.times(3, function(n: number) { this.cast(n); }, mage); + ////////////////////////////////////////////////////////////////////////////////////////////////// var iceCream = { flavor: "chocolate" }; diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 8bfb60b1a..4f32ef597 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2825,20 +2825,23 @@ declare module _ { sourceURL?: string, variable?: string): any /* string or TemplateExecutor*/; - - - - - - /** - * Invokes the given iterator function n times. - * Each invocation of iterator is called with an index argument - * @param n Number of times to invoke `iterator`. - * @param iterator Function iterator to invoke `n` times. - * @param context `this` object in `iterator`, optional. + * Executes the callback n times, returning an array of the results of each callback execution. + * The callback is bound to thisArg and invoked with one argument; (index). + * @param n The number of times to execute the callback. + * @param callback The function called per iteration. + * @param thisArg The this binding of callback. **/ - export function times(n: number, iterator: (n: number) => TResult, context?: any): TResult[]; + export function times( + n: number, + callback: Function, + context?: any): TResult[]; + + + + + + /** * Generate a globally-unique id for client-side models or DOM elements that need one.