Created
May 29, 2014 10:23
-
-
Save kobake/5b3f9253d06e9b0ae717 to your computer and use it in GitHub Desktop.
関数コールの監視その1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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