mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
- Proto chain safe - Memoized method is ready right after first access (previously it was bundled on first invokation which was problematic) - memoize when used with method option returns object with name -> descriptor content, it should be used with Object.defineProperties on target object
35 lines
765 B
JavaScript
35 lines
765 B
JavaScript
'use strict';
|
|
|
|
var memoize = require('../../lib');
|
|
|
|
module.exports = function () {
|
|
return {
|
|
"No descriptor": function (a) {
|
|
var x = {}, i = 0, fn = function () {
|
|
++i;
|
|
return this;
|
|
};
|
|
|
|
Object.defineProperties(x, memoize(fn, { method: 'foo' }));
|
|
a(x.foo(), x, "Context");
|
|
a(x.foo(), x, "Method");
|
|
a(i, 1, "Cached");
|
|
},
|
|
"Descriptor": function (a) {
|
|
var x = {}, i = 0, fn = function () {
|
|
++i;
|
|
return this;
|
|
};
|
|
|
|
Object.defineProperties(x, memoize(fn,
|
|
{ method: 'foo', writable: false }));
|
|
a(x.foo(), x, "Context");
|
|
a.deep(Object.getOwnPropertyDescriptor(x, 'foo'),
|
|
{ enumerable: false, configurable: true, writable: false,
|
|
value: x.foo });
|
|
a(x.foo(), x, "Method");
|
|
a(i, 1, "Cached");
|
|
}
|
|
};
|
|
};
|