From f65e40b856163e989cddd7a3572090130f77266f Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Fri, 18 Oct 2013 23:50:39 -0400 Subject: [PATCH] added _.once definition --- lodash/lodash-tests.ts | 4 +++- lodash/lodash.d.ts | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index c2cb46646..5d086b9ce 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -484,7 +484,9 @@ stooge('curly'); stooge['cache']['curly'].name = 'jerome'; stooge('curly'); - +var initialize = _.once(function(){ }); +initialize(); +initialize(); //////////////////////////////////////////////////////////////////////////////////////// //WHAT'S LEFT diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 4c0dd7a4a..3ea1b4813 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1859,7 +1859,14 @@ declare module _ { func: Function, resolver?: (n: any) => string): Function; - + /** + * Creates a function that is restricted to execute func once. Repeat calls to the function + * will return the value of the first call. The func is executed with the this binding of the + * created function. + * @param func Function to only execute once. + * @return The new restricted function. + **/ + export function once(func: Function): Function; @@ -1947,14 +1954,7 @@ declare module _ { wait: number, options?: ThrottleSettings): Function; - /** - * Creates a version of the function that can only be called one time. Repeated calls to the modified - * function will have no effect, returning the value from the original call. Useful for initialization - * functions, instead of having to set a boolean flag and then check it later. - * @param fn Function to only execute once. - * @return Copy of `fn` that can only be invoked once. - **/ - export function once(fn: Function): Function; +