Underscore 1.0.4, with _.memoize

This commit is contained in:
Jeremy Ashkenas
2010-06-22 09:21:03 -04:00
parent d62906672b
commit 29e2c832bc
6 changed files with 68 additions and 29 deletions

View File

@@ -45,6 +45,15 @@ $(document).ready(function() {
equals(curly.sayHi(), 'hi: moe', 'calling bindAll with no arguments binds all functions to the object');
});
test("functions: memoize", function() {
var fib = function(n) {
return n < 2 ? n : fib(n - 1) + fib(n - 2);
};
var fastFib = _.memoize(fib);
equals(fib(10), 55, 'a memoized version of fibonacci produces identical results');
equals(fastFib(10), 55, 'a memoized version of fibonacci produces identical results');
});
asyncTest("functions: delay", function() {
var delayed = false;
_.delay(function(){ delayed = true; }, 100);