请教下关于node继承的问题,为何使用了inherits还要在给构造方法里面使用父类的构造方法

function ReadStream() {
stream.Readable.call(this);
}
util.inherits(ReadStream,stream.Readable);

------------------------------
var util = require('util');
var ConstructorA = function () {
    this.func1 = function () {
        console.log('im func1!!');
    }
};
ConstructorA.prototype.func2 = function () {
    console.log('im func2!!');
};

var ConstructorB = function () {
    //ConstructorA.call(this);
};

util.inherits(ConstructorB, ConstructorA);

var conb = new ConstructorB();
conb.func2();//正常。如果util.inherits(ConstructorB, ConstructorA);被注释了,这句将报错
conb.func1();//报错,上面ConstructorB里面注释的一行打开过后,这里就不报错了。
不掉用 父类的构造方法 只能继承原型链上的属性。没法仿问 函数内定义的内部属性。
posted @ 2017-07-17 22:57  钱钱钱啊  阅读(255)  评论(0)    收藏  举报