셈플
var traceback = require("traceback");
function start() { first() }
function first() { second() }
var second = function() { last() }
function last() {
var stack = traceback();
console.log("I am " + stack[0].name + " from file " + stack[0].file)
for(var i = 1; i <= 3; i++)
console.log(" " + i + " above me: " + stack[i].name
+ " at line " + stack[i].line+" path "+stack[i].path);
}
start();
실행 결과
[root@redjini source]# ../bin/node test.js
I am last from file test.js
1 above me: second at line 5 path /data/NodeJS/source/test.js
2 above me: first at line 4 path /data/NodeJS/source/test.js
3 above me: start at line 3 path /data/NodeJS/source/test.js
I am last from file test.js
1 above me: second at line 5 path /data/NodeJS/source/test.js
2 above me: first at line 4 path /data/NodeJS/source/test.js
3 above me: start at line 3 path /data/NodeJS/source/test.js
참고 :
"JavaScript / Node.JS" 분류의 다른 글
| [node.js] ajax로 타 도메인과 연동 문제 / CORS(Cross-Origin Resource Sharing) (0) | 2013/12/20 |
| [node.js] cluster를 이용한 멀티코어(multi-core) 사용 (0) | 2013/10/22 |
| [node.js] log4js PatternLayout 사용하기 (0) | 2013/10/21 |
| [node.js] Strict mode (0) | 2013/10/21 |