I have the following code snippet
function receiver(callback)
{
console.log( callback );
}
function callback(){}
receiver( new callback() );
OUTPUT: callback {}
is there a method or way to get 'callback' out of callback parameter? I like to get an object's name.
> function callback(){}
undefined
> a = new callback();
[object Object]
> a.constructor.name
callback>
But, it won't work for any anonymous functions (everything is in the title):
> callback = function(){};
function () {}
> c = new callback();
[object Object]
> c.constructor.name
(empty string)
Try:
function receiver(callback){
console.log(callback.constructor.name);
}
function callback(){}
receiver(new callback());
Have a look at: javascript introspection in 90 seconds
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