Skip to content

Instantly share code, notes, and snippets.

@kobake
Created May 29, 2014 10:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kobake/5b3f9253d06e9b0ae717 to your computer and use it in GitHub Desktop.
Save kobake/5b3f9253d06e9b0ae717 to your computer and use it in GitHub Desktop.
関数コールの監視その1
// window配下の関数すべてにログ関数を仕込む
// ※仕込む必要ないやつは名前判定でスキップする
function watchFunctions(loggingFn) {
var name, fn;
for (name in window) {
fn = window[name];
if (typeof fn === 'function') {
// ログ出力したくない関数をここでスキップ
if(name == 'setTimeout') continue;
if(name == 'clearTimeout') continue;
if(name == 'DOMEvent') continue;
if(name == 'typeOf') continue;
if(name == 'instanceOf') continue;
// 関数ラップ
window[name] = (function(name, fn) {
var args = arguments;
return function() {
loggingFn.apply(this, args);
return fn.apply(this, arguments);
}
})(name, fn);
}
}
}
// ログ出力関数
function logging(name, fn) {
console.log("-------- calling " + name + " --------");
}
// 登録実行
watchFunctions(logging);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment