把持客栈跟踪
膳绫擎烦琐了那么多,压轴的重头戏来了,那就是若何把持客栈跟踪。
本章专门针对那些像NodeJS支Error.captureStackTrace的情况。
Error.captureStackTrace函数接收一个object作为第一个参数,第二个参数是可选的,接收一个函数。capture stack trace 捕获当前客栈跟踪,并在目标对象中创建一个stack属性来存储它。如不雅供给了第二个参数,则传递的函数将被视为调用客栈的终点,是以客栈跟踪将仅显示调用该函数之前产生的调用。
让我们用例子来解释这一点。起首,我们将捕获当前客栈跟踪并将其存储在公共对象中。
- const myObj = {};
- function c() {
- }
- function b() {
- // Here we will store the current stack trace into myObj
- Error.captureStackTrace(myObj);
- c();
- }
- function a() {
- b();
- }
- // First we will call these functions
- a();
- // Now let's see what is the stack trace stored into myObj.stack
- console.log(myObj.stack);
- // This will print the following stack to the console:
- // at b (repl:3:7) <-- Since it was called inside B, the B call is the last entry in the stack
- // at a (repl:2:1)
- // at repl:1:1 <-- Node internals below this line
- // at realRunInThisContextScript (vm.js:22:35)
- // at sigintHandlersWrap (vm.js:98:12)
- // at ContextifyScript.Script.runInThisContext (vm.js:24:12)
- // at REPLServer.defaultEval (repl.js:313:29)
- // at bound (domain.js:280:14)
- // at
推荐阅读
近些年来,深度卷积神经收集(DCNN)在图像分类和辨认上取得了很明显的进步。回想大年夜 2014 到 2016 这两年多的时光,先后出现出了 R-CNN,Fast R-CNN, Faster R-CNN, ION, HyperNet, SD>>>详细阅读
地址:http://www.17bianji.com/lsqh/34953.html
1/2 1