手間がかからないものは思いつきません。これが私の最初の失敗した試みです。ウィンドウのすべての内部プロパティを反復しようとすると、無限再帰になります。
/**
* You have to run this in firefox, pass window the first time
* @return boolean Whether the given object contains a function where its
* source code contains the word console.
*/
function lookForConsole( obj ) {
var found = false;
for (var prop in obj) {
var current = obj[prop];
if (typeof current == "function") {
if (current.toSource.indexOf("console" + ".log") != -1) {
found = true;
break;
}
} else if (typeof current == "object"){
found = lookForConsole(current);
if (found) {
break;
}
}
}
return found;
}
「道具がハンマーしかないとき、すべての問題は釘のように見える」という表現を聞いたことがありますか?
なぜJSでこれを行うのですか?