在JavaScript中,假设您有:有没有办法查看一个(匿名)函数?
function doSomething(callback) {
if (callback instanceof Function) callback();
}
doSomething(function() {
alert('hello world');
});
有没有一种方法来检查里面是什么“回调”(喜欢,事实证明alert()
叫)从doSomething()
?喜欢的东西:
function doSomething(callback) {
alert(callback.innards().indexOf('alert('));
}
我只是好奇
你为什么想要做这样的事情? – asawyer
关于typeof与instanceof的很好的讨论在这里:http://stackoverflow.com/questions/899574/which-is-best-to-use-typeof-or-instanceof – ScottE