這是一個選擇,不能完全肯定這是雖然有多可靠,感覺有點不對勁:
(function() {
var oldCall = Function.prototype.call;
var newCall = function(self) {
Function.prototype.call = oldCall;
console.log('Function called:', this.name);
var args = Array.prototype.slice.call(arguments, 1);
Function.prototype.call = newCall;
this.apply(self, args);
}
Function.prototype.call = newCall;
})();
正如你所看到的,它覆蓋call
功能 - 這創造了一個小問題當您嘗試撥打console.log()
時,您需要將功能交換回去。但它似乎工作!
編輯
由於這是標記的CoffeeScript:
do ->
oldCall = Function::call
newCall = (self) ->
Function::call = oldCall
console.log "Function called: #{this.name}"
args = Array.prototype.slice.call arguments, 1
Function::call = newCall
this.apply self, args
Function::call = newCall
的可能的複製[如何調試的Node.js應用程序?(http://stackoverflow.com/questions/1911015/how-do-i-debug-node-js-應用程序) – Sylar 2016-06-27 16:54:23