// 📁 index.js
const { saveCallHistory } = require('./saveCallHistory.js');
// function
function f(...args) {
return args.join();
}
// object
let user = {
// method
say(...args) { return args.join() }
};
// ⭐️ decorator: "saveCallHistory"
// ⭐️ make function/method save call history
f = saveCallHistory(f);
user.say = saveCallHistory(user.say);
// log
[
f(1),
f(1,2),
f.history, // [ [ 1 ], [ 1, 2 ] ]
user.say(0),
user.say(2, 3),
user.say(4, 5, 6),
user.say.history, // [ [ 0 ], [ 2, 3 ], [ 4, 5, 6 ] ]
].forEach(x => console.log(x));