logging - How to create a logger for a javascript arrow function? -
is there way implement logger function can intercept arrow functions example bellow? i
original code:
const arrowfunctionexample = (value)=> { console.log('arrowfunctionexample',value) } function main(){ arrowfunctionexample('testing') }
new code:
const arrowfunctionexample = (value)=> { console.log('arrowfunctionexample',value) } function main(){ logger(arrowfunctionexample('testing')) } //something const logger = (fn) => { console.log('logger',fn) if( typeof fn === 'function'){ fn(value) } }
i want same effect when main execution in both cases, without having edit arrows functions.
is want ?
function logger(fn){ return function(){ console.log("log:", fn.name, arguments); return fn.apply(this, arguments); } } const arrowfunctionexample = (value)=> { console.log("do with", value); }; function main(){ logger(arrowfunctionexample)('testing') } main();
Comments
Post a Comment