1.3.8

Back | Minified | Changelog | Cautionlog
2013-01-13

New caching mechanism

The Function#throttle method was intended as a way to rate limit heavy operations, however not much thought was given to the returned value. v1.3.8 adds a mechanism that memoizes the result of a throttled function so that it will always return the last calculated value. This means that it can now be used as a way to cache a value for a specific period of time:

var cachedOperation = heavyOperation.throttle(5000); cachedOperation(); // Runs the operation cachedOperation(); // Returns the result of the last operation setTimeout(function() { cachedOperation(); // Runs the operation again }, 6000);

Function#once now makes use of this mechanism internally. It is now equivalent to .throttle(Infinity), or in other words a cached function that never expires.

Bugfixes