When I am printing helpful errors in my program, I want to print along the method name. So for example in the mock code below when console logging inside goodMorning
, I want to embed the name 'goodMorning' or 'Hello.goodMorning' in the print out by calling a getMethodName
function; the function now simply returns 'goodMorning' but I want it to return the name of whatever method it is called in (it may need to take some argument to do that).
const getMethodName = () => {
return 'goodMorning'
}
class Hello {
goodMorning () {
console.log(`I am inside ${getMethodName()} method`)
}
}
new Hello().goodMorning()