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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -