I'm not sure this kind of feature is available in Javascript. Here is what I wanted to archive.
Let's say we have an object instance called obj
and I want to call any function in this object instance but I'm not defining the function name at the beginning.
const obj = {};
obj.functionOne({id: 1}); // execution 1
obj.functionTwo({id: 1}); // execution 2
I wanted to execute one single function (_default
) for both execution 1
and execution 2
. withing that function I need to know what is the function name actually executed.
eg:
obj = {
_default: (params) {
console.log('Function Name is', Function.name); // will be print `functionOne` or `functionTwo`
console.log(params); // will be print {id: 1} for both cases.
}
}
Can someone give me some insight on how to archive this kind of requirement?
Thanks in advance.