現在の関数を呼び出す関数の名前と行を取得するにはどうすればよいですか?私は(npmlogがlog.debug
を定義して)このように、基本的なデバッグ機能を持っているしたいと思います:node.jsの名前と関数の呼び出しを取得します
function debug() {
var callee, line;
/* MAGIC */
log.debug(callee + ":" + line, arguments)
}
別の関数から呼び出された場合、それはこのようなものになるだろう:私が欲しいものを、明確にするために
function hello() {
debug("world!")
}
// outputs something like:
// "hello:2 'world!'"
本質的にはthis in Pythonに似ています。
import inspect
def caller():
return inspect.stack()[2][3]
// line no from getframeinfo().lineno
これを達成するために同等のノードはありますか?
これは便利かもしれないが、私は同様の質問をしたが、関連するノードではありません。http://stackoverflow.com/questions/6885659/determining-source-line-and-file-of-function-reference-how -does-firebug-do-it –