Closed jdylanstewart closed 7 years ago
In memoizee function is treated as nothing more than a function, and I would prefer not to extend library with logic as proposed.
Mainly to not introduce additional level of complexity, but it also may appear as not that straightforward as it seems, I can imagine cases when such behaviour may be unwanted.
Use cases are rare, and if you really need it, you can on your own introduce a decorator that will do it cleanly:
var memoizePlus = function (fn) {
var memoized = memoize.apply(this, arguments);
Object.keys(fn).forEach(function (key) { memoized[key] = fn[key]; });
return memoized;
};
var memoized = memoizePlus(fn, ...); // does what you need
memoizedFunc
does not retain thestate
property.This should be as simple as iterating through keys and applying them to the memoized function.
Object.keys(func).forEach((key) => { returnFunc[key] = newFunc[key] })