diff --git a/lib/primitive.js b/lib/primitive.js index 0f0ef0d..aeb87f7 100644 --- a/lib/primitive.js +++ b/lib/primitive.js @@ -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) { diff --git a/test/primitive.js b/test/primitive.js index 557d396..375abc4 100644 --- a/test/primitive.js +++ b/test/primitive.js @@ -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'; } };