๐พsaveCallHistory(f)
make a function/method save its call history (arguments).
JS โฉ technique โฉ decorator โฉ ๐พ saveCallHistory(f)
replit๏ผsaveCallHistory(f)
// ๐ saveCallHistory.js
const {log} = console;
// throttle decorator
function saveCallHistory(f){
// โญ๏ธ save call history (arguments) here
let history = [];
// ๐ธ wrapper.history (getter)
Object.defineProperty(wrapper, 'history', {
get() { return history }
})
return wrapper;
// โญ๏ธ decorated function
function wrapper(...args){
history.push(args); // save arguments first
return f.apply(this, args);
}
}
// export
module.exports = { saveCallHistory }
Last updated
Was this helpful?