added _.partial definitions, more forgotten type castings in tests

This commit is contained in:
Brian Zengel
2013-10-18 23:55:30 -04:00
parent f65e40b856
commit 557389c808
2 changed files with 70 additions and 65 deletions
+7 -3
View File
@@ -469,7 +469,7 @@ result = <number>_.defer(function() { console.log('deferred'); });
var log = _.bind(console.log, console);
result = <number>_.delay(log, 1000, 'logged later');
var fibonacci = _.memoize(function(n) {
var fibonacci = <Function>_.memoize(function(n) {
return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
});
@@ -478,16 +478,20 @@ var data = {
'curly': { 'name': 'curly', 'age': 60 }
};
var stooge = _.memoize(function(name) { return data[name]; }, _.identity);
var stooge = <Function>_.memoize(function(name) { return data[name]; }, _.identity);
stooge('curly');
stooge['cache']['curly'].name = 'jerome';
stooge('curly');
var initialize = _.once(function(){ });
var initialize = <Function>_.once(function(){ });
initialize();
initialize();
var greetPartial = function(greeting, name) { return greeting + ' ' + name; };
var hi = <Function>_.partial(greetPartial, 'hi');
hi('moe');
////////////////////////////////////////////////////////////////////////////////////////
//WHAT'S LEFT
////////////////////////////////////////////////////////////////////////////////////////
+63 -62
View File
@@ -1868,74 +1868,75 @@ declare module _ {
**/
export function once(func: Function): Function;
/**
* Partially apply a function by filling in any number of its arguments, without changing its dynamic this value.
* A close cousin of bind.
* @param fn Function to partially fill in arguments.
* @param arguments The partial arguments.
* @return `fn` with partially filled in arguments.
* Creates a function that, when called, invokes func with any additional partial arguments
* prepended to those provided to the new function. This method is similar to _.bind except
* it does not alter the this binding.
* @param func The function to partially apply arguments to.
* @param args Arguments to be partially applied.
* @return The new partially applied function.
**/
export function partial(
fn: Function,
...arguments: any[]): Function;
/**
* Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly,
* will only actually call the original function at most once per every wait milliseconds. Useful for