Closed pauldijou closed 4 years ago
Thanks for the clear explanation!
Side note, I'm not sure if worth fixing it, but if arg is undefined on the first call, then if will match the initial prevArg and directly return value (which is also undefined). I don't think anything is preventing users from having an initial undefined state, might not happen a lot though. One easy way to fix it would be to create whatever object and assigning to let prevArg: AT = initialPrevArg; so that the strict equality can never yield true on the first call.
Great point, I think assigning an empty object would be reasonable, with a good comment.
Cool. I will do another pull request for the initial prevArg.
Before, if by any chance, the
fn
function was to throw, the argument would have been saved intoprevArg
, resulting in returningvalue
from the previous call if it was to be called again with the same argument after that.Side note, I'm not sure if worth fixing it, but if
arg
isundefined
on the first call, then if will match the initialprevArg
and directly returnvalue
(which is alsoundefined
). I don't think anything is preventing users from having an initialundefined
state, might not happen a lot though. One easy way to fix it would be to create whatever object and assigning tolet prevArg: AT = initialPrevArg;
so that the strict equality can never yieldtrue
on the first call.