Node.js util.inspect输出澄清

时间:2014-06-23 18:51:44

标签: node.js output

我知道有很多关于这个主题的问题,但我已经仔细阅读了这些内容,并且我看到了这个函数的输出没有被提及。

我在对象上运行util.inspect

util.inspect(xyz, { showHidden: true });

得到这样的输出:

{ [Function: foo]
  [name]: foo,
  [arguments]: bar,
  [prototype]: 
   { foobarize: 
      { [Function: foobarize]
        [length]: 99,
        [name]:  foobarize,
        [prototype]: [Object]
      },
      [constructor]: foob
    }
 }

在对象foobarize()上运行xyz需要哪些命令?

2 个答案:

答案 0 :(得分:1)

我自己找到了解决方案。它是为了做到以下几点:

xyz.prototype.foobarize();

答案 1 :(得分:0)

对象的prototype上的任何内容都可以按实例调用。

// foo is defined
var inst_foo = new foo();
inst_foo.foobarize(); // calls foobarize() from instance

这比从蓝图函数(对象定义)prototype调用它更面向对象。