added _.times definition

This commit is contained in:
Brian Zengel
2013-10-20 20:10:51 -04:00
parent 39b96f597c
commit 2fd84867f3
2 changed files with 24 additions and 12 deletions
+9
View File
@@ -760,6 +760,15 @@ result = <_.TemplateExecutor>_.template('hello <%= name %>', null, { 'sourceURL'
result = <_.TemplateExecutor>_.template('hi <%= data.name %>!', null, { 'variable': 'data' });
result = <string>(<_.TemplateExecutor>result).source;
function Mage() {
this.castSpell = (n:number) => n;
this.cast = (n: number) => n;
};
var mage = new Mage();
result = <any[]>_.times(3, _.partial(_.random, 1, 6));
result = <any[]>_.times(3, function(n: number) { mage.castSpell(n); });
result = <any[]>_.times(3, function(n: number) { this.cast(n); }, mage);
//////////////////////////////////////////////////////////////////////////////////////////////////
var iceCream = { flavor: "chocolate" };
+15 -12
View File
@@ -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<TResult>(n: number, iterator: (n: number) => TResult, context?: any): TResult[];
export function times<TResult>(
n: number,
callback: Function,
context?: any): TResult[];
/**
* Generate a globally-unique id for client-side models or DOM elements that need one.