A function is getting called multiple times is there a way to store the context/arguments of last function call and check with current ones.
When defining the function, I'd use a closure to store a persistent variable, reassigned to the arguments passed on every call, eg:
const fn = (() => {
let lastArgs;
return (...args) => {
console.log('function was called with args:', args);
console.log('past args were:', lastArgs);
lastArgs = args;
};
})();
fn('foo', 'bar');
fn('baz');
You can use a global variable for storing data. Everytime a new function called check new arguments with global variable and do what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With