在node.js中,是否有类似于Python中的inspect.stack()
和inspect.currentFrame()
的东西?
例如,捕获代码上下文/帧/检查事件对象。
最佳答案
您可以使用new Error().stack
来检查堆栈:
console.log(new Error().stack);
打印:
Error
at repl:1:13
at sigintHandlersWrap (vm.js:22:35)
at sigintHandlersWrap (vm.js:96:12)
at ContextifyScript.Script.runInThisContext (vm.js:21:12)
at REPLServer.defaultEval (repl.js:313:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:513:10)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:188:7)
有一个可以运行的 Node 调试器:
node debug script.js
参见:
您还可以使用 Chrome 开发者工具通过以下方式实时检查所有内容:
node --inspect script.js
参见:
- Debugging Node.js in Chrome DevTools作者:马特·德斯劳里尔斯
- Debugging Node.js with Chrome DevTools 作者:保罗·爱尔兰
关于javascript - 检查 Node.js 中的事件对象/堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41279529/