至此你应当会问本身:“这到底有什么竽暌姑?”。这异常有效,因为你可以用它来隐蔽与用户无关的内部实现细节。在Chai中,我们应用它来避免向用户显示我们是若何实施检查和断言本身的不相干的细节。
操作客栈追踪拭魅战
- // `ssfi` stands for "start stack function". It is the reference to the
- // starting point for removing irrelevant frames from the stack trace
- function AssertionError (message, _props, ssf) {
- var extend = exclude('name', 'message', 'stack', 'constructor', 'toJSON')
- , props = extend(_props || {});
- // Default values
- this.message = message || 'Unspecified AssertionError';
- this.showDiff = false;
- // Copy from properties
- for (var key in props) {
- this[key] = props[key];
- }
- // Here is what is relevant for us:
- // If a start stack function was provided we capture the current stack trace and pass
- // it to the `captureStackTrace` function so we can remove frames that come after it
- ssf = ssf || arguments.callee;
- if (ssf && Error.captureStackTrace) {
- Error.captureStackTrace(this, ssf);
- } else {
- // If no start stack function was provided we just use the original stack property
- try {
- throw new Error();
- } catch(e) {
- this.stack = e.stack;
- }
- }
- }
如你所见,我们应用Error.captureStackTrace捕获客栈追踪并将它存储在我们正在创建的AssertError实例中(如不雅存在的话),然后我们将一个肇端客栈函数传递给它,以便大年夜客栈跟踪中删除不相干的调用帧,它只显示Chai的内部实现细节,最终使客栈变得清楚清楚明了。
推荐阅读
近些年来,深度卷积神经收集(DCNN)在图像分类和辨认上取得了很明显的进步。回想大年夜 2014 到 2016 这两年多的时光,先后出现出了 R-CNN,Fast R-CNN, Faster R-CNN, ION, HyperNet, SD>>>详细阅读
地址:http://www.17bianji.com/lsqh/34953.html
1/2 1

网友点评
精彩导读
科技快报
品牌展示