fix: _get and _has internal args handling.

Fixes #88
This commit is contained in:
Mariusz Nowak
2017-09-11 13:05:30 +02:00
parent 71da72cddf
commit 7cb1c7a603
2 changed files with 25 additions and 2 deletions

View File

@@ -162,14 +162,18 @@ module.exports = function (original, length, options) {
}
extGet = defineLength(function () {
var id, args = arguments;
if (length === 0) return cache.data;
if (resolve) args = resolve(args);
id = get(args);
if (get) id = get(args);
else id = String(args[0]);
return cache[id];
});
extHas = defineLength(function () {
var id, args = arguments;
if (length === 0) return conf.has("data");
if (resolve) args = resolve(args);
id = get(args);
if (get) id = get(args);
else id = String(args[0]);
if (id === null) return false;
return conf.has(id);
});

View File

@@ -24,6 +24,25 @@ module.exports = function () {
a(mfn("foo"), y, "#2");
a(i, 1, "Called once");
},
"No args": function (a) {
var i = 0
, fn = function () {
++i;
return "foo";
}
, mfn
, y = {
toString: function () {
return "foo";
}
};
mfn = memoize(fn);
a(mfn._has(), false);
a(mfn(), "foo", "#1");
a(mfn._has(), true);
mfn();
a(i, 1, "Called once");
},
"Clear cache": function (a) {
var i = 0
, fn = function (x, y, z) {