In JavaScript, let’s say you have:
function doSomething(callback) {
if (callback instanceof Function) callback();
}
doSomething(function() {
alert('hello world');
});
Is there a way to check what is inside ‘callback’ (like, the fact that alert() is called) from doSomething()? Something like:
function doSomething(callback) {
alert(callback.innards().indexOf('alert('));
}
I’m just curious
Function.prototype.toString() gives an
implementation-dependent representation of the function. However built-in functions will return something like:and host methods can return anything, even throw an error. So the strict answer is yes, maybe. But in a practical sense, it is not reliable.