underscore-source 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Underscore
2
2
  module Source
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
@@ -55,7 +55,7 @@
55
55
  root._ = _;
56
56
 
57
57
  // Current version.
58
- _.VERSION = '1.0.3';
58
+ _.VERSION = '1.0.4';
59
59
 
60
60
  // ------------------------ Collection Functions: ---------------------------
61
61
 
@@ -375,6 +375,16 @@
375
375
  return obj;
376
376
  };
377
377
 
378
+ // Memoize an expensive function by storing its results.
379
+ _.memoize = function(func, hasher) {
380
+ var memo = {};
381
+ hasher = hasher || _.identity;
382
+ return function() {
383
+ var key = hasher.apply(this, arguments);
384
+ return key in memo ? memo[key] : (memo[key] = func.apply(this, arguments));
385
+ };
386
+ };
387
+
378
388
  // Delays a function for the given number of milliseconds, and then calls
379
389
  // it with the arguments supplied.
380
390
  _.delay = function(func, wait) {
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: underscore-source
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.3
5
+ version: 1.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Daniel X. Moore