Cer*_*nce 17
定义函数时,我将使用闭包存储持久变量,并将其重新分配给每次调用传递的参数,例如:
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');Run Code Online (Sandbox Code Playgroud)