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

在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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值