mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
Fix primitive handling for dynamic length
This commit is contained in:
@@ -17,8 +17,8 @@ module.exports = require('./_base')(function (conf, length) {
|
||||
if (length === 1) {
|
||||
get = conf.get = getId1;
|
||||
} else if (length === false) {
|
||||
get = conf.get = function (args, length) {
|
||||
var id = '', i;
|
||||
get = conf.get = function (args) {
|
||||
var id = '', i, length = args.length;
|
||||
if (length) {
|
||||
id += args[i = 0];
|
||||
while (--length) {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var join = Array.prototype.join;
|
||||
|
||||
module.exports = function (t) {
|
||||
return {
|
||||
"No args": function (a) {
|
||||
@@ -25,6 +27,18 @@ module.exports = function (t) {
|
||||
a(mfn('foo', 'bar', 'zeta'), 'foobarzeta', "#2");
|
||||
a(i, 1, "Called once");
|
||||
},
|
||||
"Many args: Length false": function (a) {
|
||||
var i = 0, fn = function () { ++i; return join.call(arguments, '|'); }
|
||||
, y = { toString: function () { return 'foo'; } }, mfn;
|
||||
mfn = t(fn, { primitive: true, length: false });
|
||||
a(mfn(y, 'bar', 'zeta'), 'foo|bar|zeta', "#1");
|
||||
a(mfn('foo', 'bar', 'zeta'), 'foo|bar|zeta', "#2");
|
||||
a(i, 1, "Called once");
|
||||
a(mfn(y, 'bar'), 'foo|bar', "#3");
|
||||
a(i, 2, "Called twice");
|
||||
a(mfn(y, 'bar'), 'foo|bar', "#4");
|
||||
a(i, 2, "Called twice #2");
|
||||
},
|
||||
"Clear cache": function (a) {
|
||||
var i = 0, fn = function (x, y, z) { ++i; return x + y + z; }, mfn
|
||||
, y = { toString: function () { return 'foo'; } };
|
||||
|
||||
Reference in New Issue
Block a user