I've created a function and bound the arguments as below.
function myFunc(){}
let boundFunc = myFunc.bind(argument);
But then I pass this bound function as an argument to another function, where I need to get the name. The following:
function doTheThing(callable){
console.log(callable.name + " did the thing");
}
doTheThing(boundFunc);
Prints out bound did the thing
rather than myFunc did the thing
. Is there any way to get the name of the bound function?
callable.caller
results in Uncaught TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context.
and is not browser standard.
Google Chrome v 51.0.2704.103 gives a different result:
function myFunc(){}
let boundFunc = myFunc.bind(null);
function doTheThing(callable){
console.log(callable.name + " did the thing");
}
doTheThing(boundFunc);
It prints bound myFunc did the thing
, so you could get the original name with callable.name.substring(6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With