为什么这个模块的__proto__为空?

时间:2014-10-11 01:10:09

标签: node.js

我正在尝试更好地理解JS对象,并正在尝试使用node {j}的pg module。我的问题是,为什么创建的对象没有__proto__属性?

var pg = require('pg');

console.log('proto: %j', pg.__proto__);

if ('connect' in pg) {
    console.log("connect exists");
}

我运行nodejs test.js时的输出是:

proto: {}
connect exists

在pg模块本身中,我可以看到connect方法附加到构造函数的原型:

PG.prototype.connect = function(config, callback) {

我的pg对象使用此connect方法但有一个空的__proto__会发生什么魔法?

1 个答案:

答案 0 :(得分:1)

console.log将结果%j替换为JSON.stringify。 JSON不支持函数,因此省略它们。只需查看typeof pg.__proto__.connect === 'function'

即可