不知道你留意到没,我们起首调用了a(a入栈),然后我们a中又调用了b(b入栈且在a之上)。然后在b中我们捕获了当前客栈记录并将其存储在myObj中。是以在控制台中才会按照b a的次序打印客栈。
如今让我们给Error.captureStackTrace传递一个函数作为第二个参数,看看会产生什么:
- const myObj = {};
- function d() {
- // Here we will store the current stack trace into myObj
- // This time we will hide all the frames after `b` and `b` itself
- Error.captureStackTrace(myObj, b);
- }
- function c() {
- d();
- }
- function b() {
- 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 a (repl:2:1) <-- As you can see here we only get frames before `b` was called
- // 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 REPLServer.runBound [as eval] (domain.js:293:12)
- // at REPLServer.onLine (repl.js:513:10)
- // at emitOne (events.js:101:20)
当把b传给Error.captureStackTraceFunction时,它隐蔽了b本身以及它之后所有的调用帧。是以控制台仅仅打印出一个a。
推荐阅读
近些年来,深度卷积神经收集(DCNN)在图像分类和辨认上取得了很明显的进步。回想大年夜 2014 到 2016 这两年多的时光,先后出现出了 R-CNN,Fast R-CNN, Faster R-CNN, ION, HyperNet, SD>>>详细阅读
地址:http://www.17bianji.com/lsqh/34953.html
1/2 1