我正在尝试以这种方式使用模块模式实现继承:
Parent = function () {
//constructor
(function construct () {
console.log("Parent");
})();
// public functions
return this.prototype = {
test: function () {
console.log("test parent");
},
test2: function () {
console.log("test2 parent");
}
};
};
Child = function () {
// constructor
(function () {
console.log("Child");
Parent.call(this, arguments);
this.prototype = Object.create(Parent.prototype);
})();
// public functions
return this.prototype = {
test: function()
{
console.log("test Child");
}
}
};
但我不能从孩子的实例中调用test2()
.
var c = new Child();
c.test2(); // c.test2 is not a function
我错了什么?