Files
memoizee/test/ext/method.js
Mariusz Nowak fb4439692d Improve 'method' functionality.
- 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
2013-02-11 17:43:55 +01:00

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");
}
};
};