Closed diegosanchez closed 8 years ago
It's expected, as in both cases you pass different objects, therefore different arguments. It will pass if it would be done as following:
var obj = { x: 1, y: 1 };
mf(1, obj); // miss
mf(1, obj); // hit
You can however provide your own normalizer, so even if they're different object, they're recognized as same ones:
var mf = m(f, { normalizer: function (args): {
return String(args[0]) + JSON.stringify(args[1]);
} });
mf(1,{ x:1, y:1}); // miss
mf(1,{ x:1, y:1}); // hit
Memoize works with strings and numbers but not with more complex parameters like objects like
{x:1, y: 1}
Here the pice of code:
I will be nice to have deep comparison, won't it? May be there is a performance consideration to have.