javascript 堆栈
I recently inherited a Node.js project and man is that scary. The code was well written but whenever you inherit a project you instantly inherit the fear of messing things up. My goal was to fix a fairly routine bug, and finding the issue was fairly easy, but tracing through the code to figure out what called what and what passed what was a nightmare.
我最近继承了一个Node.js项目,可真是吓人。 代码写得很好,但是每当您继承一个项目时,您都立即继承了将事情弄乱的恐惧。 我的目标是修复一个相当常规的错误,并且发现问题相当容易,但是要遍历代码以找出所谓的内容和经历了噩梦的内容。
So I did the only thing I could do to figure out WTF was going on:
因此,我做了唯一能弄清楚WTF正在进行的事情:
// The magic console.log(new Error().stack); /* SAMPLE: Error at Object.module.exports.request (/home/vagrant/src/kumascript/lib/kumascript/caching.js:366:17) at attempt (/home/vagrant/src/kumascript/lib/kumascript/loaders.js:180:24) at ks_utils.Class.get (/home/vagrant/src/kumascript/lib/kumascript/loaders.js:194:9) at /home/vagrant/src/kumascript/lib/kumascript/macros.js:282:24 at /home/vagrant/src/kumascript/node_modules/async/lib/async.js:118:13 at Array.forEach (native) at _each (/home/vagrant/src/kumascript/node_modules/async/lib/async.js:39:24) at Object.async.each (/home/vagrant/src/kumascript/node_modules/async/lib/async.js:117:9) at ks_utils.Class.reloadTemplates (/home/vagrant/src/kumascript/lib/kumascript/macros.js:281:19) at ks_utils.Class.process (/home/vagrant/src/kumascript/lib/kumascript/macros.js:217:15) */Of course the actual "error" doesn't matter -- the stack trace is exactly what you need to figure out what's calling what up the chain. When available you can also use console.trace() (when available) to achieve roughly the same output. You can thank me later!
当然,实际的“错误”无关紧要-堆栈跟踪正是您需要找出链中到底是什么的内容。 如果可用,您还可以使用console.trace() (如果可用)来获得大致相同的输出。 您可以稍后感谢我!
翻译自: https://davidwalsh.name/javascript-stack-trace
javascript 堆栈