>  기사  >  웹 프론트엔드  >  node.js中的console.trace方法使用说明_node.js

node.js中的console.trace方法使用说明_node.js

WBOY
WBOY원래의
2016-05-16 16:28:011545검색

方法说明:

向标准错误流输出当前的调用栈。

语法:

复制代码 代码如下:

console.trace(label)

接收参数:

label

例子:

复制代码 代码如下:

console.trace();
 
//运行结果:
Trace:
     at Object. (/home/byvoid/consoletrace.js : 1: 71)
     at Module._compile (module.js:441:26)
     at Object..js (module.js:459:10)
     at Module.load (module.js:348:31)
     at Function._load (module.js:308:12)
     at Array.0 (module.js:479:10)
     at EventEmitter._tickCallback (node.js:192:40)

源码:

复制代码 代码如下:

Console.prototype.trace = function() {
  // TODO probably can to do this better with V8's debug object once that is
  // exposed.
  var err = new Error;
  err.name = 'Trace';
  err.message = util.format.apply(this, arguments);
  Error.captureStackTrace(err, arguments.callee);
  this.error(err.stack);
};
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.