Merge pull request #5629 from chrootsu/lodash-times

lodash: changed _.times() method
This commit is contained in:
Masahiro Wakame
2015-09-03 02:15:37 +09:00
2 changed files with 46 additions and 13 deletions

View File

@@ -1735,11 +1735,6 @@ class Mage {
}
}
var mage = new Mage();
result = _.times(3, <() => number>_.partial(_.random, 1, 6));
result = _.times(3, function (n: number) { mage.castSpell(n); });
result = _.times(3, function (n: number) { this.cast(n); }, mage);
result = <string>_.uniqueId('contact_');
result = <string>_.uniqueId();
@@ -1948,3 +1943,18 @@ result = <number>(_(TestMethodOfObject).methodOf<number>(1, 2).value())(['a', '0
result = <string>_.VERSION;
result = <_.Support>_.support;
result = <_.TemplateSettings>_.templateSettings;
// _.times
{
let result: number[];
result = _.times(42);
result = _(42).times().value();
}
{
let testTimesFn: (num: number) => TResult;
let result: TResult[];
result = _.times(42, testTimesFn);
result = _.times(42, testTimesFn, any);
result = _(42).times(testTimesFn).value();
result = _(42).times(testTimesFn, any).value();
}

39
lodash/lodash.d.ts vendored
View File

@@ -8300,16 +8300,39 @@ declare module _ {
//_.times
interface LoDashStatic {
/**
* 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.
**/
* Invokes the iteratee function n times, returning an array of the results of each invocation. The iteratee is
* bound to thisArg and invoked with one argument; (index).
*
* @param n The number of times to invoke iteratee.
* @param iteratee The function invoked per iteration.
* @param thisArg The this binding of iteratee.
* @return Returns the array of results.
*/
times<TResult>(
n: number,
callback: (num: number) => TResult,
context?: any): TResult[];
iteratee: (num: number) => TResult,
thisArg?: any
): TResult[];
/**
* @see _.times
*/
times(n: number): number[];
}
interface LoDashWrapper<T> {
/**
* @see _.times
*/
times<TResult>(
iteratee: (num: number) => TResult,
thisArgs?: any
): LoDashArrayWrapper<TResult>;
/**
* @see _.times
*/
times(): LoDashArrayWrapper<number>;
}
//_.uniqueId