欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用console.dir 快速概览Node.JS中对象实例的属性和方法

程序员文章站 2022-06-15 14:56:12
...

在Node.JS命令行中输入:

> console.log(process.version)
v0.6.14
> console.dir(console)
{ log: [Function],
  info: [Function],
  warn: [Function],
  error: [Function],
  dir: [Function],
  time: [Function],
  timeEnd: [Function],
  trace: [Function],
  assert: [Function] }
undefined
>

对照上面的“索引”查看console.js更方面 

查看console.js中的dir函数定义

exports.dir = function(object) {
  process.stdout.write(util.inspect(object) + '\n');
};

 

 输入下列命令看看

> console.dir(global)

查看内置的 process 

> console.dir(process)
{ title: 'C:\\WINDOWS\\system32\\cmd.exe - node',
  EventEmitter: [Function: EventEmitter],
  version: 'v0.6.14',
  assert: [Function],
  moduleLoadList:
   [ 'Binding evals',
     'Binding natives',
     'NativeModule events',
     'NativeModule buffer',
     'Binding buffer',
     'NativeModule assert',
     'NativeModule util',
     'NativeModule module',
     'NativeModule path',
     'NativeModule tty',
     'NativeModule net',
     'NativeModule stream',
     'NativeModule timers',
     'Binding timer_wrap',
     'NativeModule _linklist',
     'Binding tty_wrap',
     'NativeModule vm',
     'NativeModule fs',
     'Binding fs',
     'Binding constants',
     'NativeModule readline',
     'NativeModule console' ],
  _tickCallback: [Function],
  nextTick: [Function],
  versions:
   { node: '0.6.14',
     v8: '3.6.6.24',
     ares: '1.7.5-DEV',
     uv: '0.6',
     openssl: '0.9.8r' },
  stdout: [Getter],
  arch: 'ia32',
  platform: 'win32',
  stderr: [Getter],
  argv: [ 'node' ],
  stdin: [Getter],
  openStdin: [Function],
  env:
   { ...
     NLS_LANG: 'SIMPLIFIED CHINESE_CHINA.ZHS16GBK',
     NUMBER_OF_PROCESSORS: '2',
     OS: 'Windows_NT',
     Path: '...//略;
     C:\\Program Files\\nodejs\\,;...//略
     PATHEXT: '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.PSC1',
     PROCESSOR_ARCHITECTURE: 'x86',
     PROCESSOR_IDENTIFIER: 'x86 Family 6 Model 23 Stepping 10, GenuineIntel',
     PROCESSOR_LEVEL: '6',
     PROCESSOR_REVISION: '170a',
     ProgramFiles: 'C:\\Program Files',
     PROMPT: '$P$G',
     ...//略
     SESSIONNAME: 'Console',
     ...//略
     windir: 'C:\\WINDOWS' },
  exit: [Function],
  pid: 2900,
  features:
   { debug: false,
     uv: true,
     ipv6: true,
     tls_npn: true,
     tls_sni: true,
     tls: true },
  kill: [Function],
  addListener: [Function],
  execPath: 'C:\\Program Files\\nodejs\\node.exe',
  _needTickCallback: [Function],
  on: [Function],
  removeListener: [Function],
  reallyExit: [Function],
  debug: [Function],
  chdir: [Function],
  error: [Function],
  cwd: [Function],
  umask: [Function],
  watchFile: [Function],
  _kill: [Function],
  unwatchFile: [Function],
  mixin: [Function],
  _debugProcess: [Function],
  dlopen: [Function],
  createChildProcess: [Function],
  uptime: [Function],
  inherits: [Function],
  _byteLength: [Function],
  memoryUsage: [Function],
  uvCounters: [Function],
  _events: { SIGWINCH: [ [Function] ] },
  binding: [Function] }
undefined

转载于:https://my.oschina.net/u/559991/blog/59821