mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Issue #306 : Switch implementation for memoizer
This commit is contained in:
16
src/js/utils/FunctionUtils.js
Normal file
16
src/js/utils/FunctionUtils.js
Normal file
@@ -0,0 +1,16 @@
|
||||
(function () {
|
||||
var ns = $.namespace('pskl.utils');
|
||||
|
||||
ns.FunctionUtils = {
|
||||
memo : function (fn, cache, scope) {
|
||||
var memoized = function () {
|
||||
var key = Array.prototype.join.call(arguments, '-');
|
||||
if (!cache[key]) {
|
||||
cache[key] = fn.apply(scope, arguments);
|
||||
}
|
||||
return cache[key];
|
||||
};
|
||||
return memoized;
|
||||
}
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user