Ich versuche, das Erbe mit dem Modul Muster auf diese Weise zu implementieren:Vererbung und Modul Muster
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");
}
}
};
aber ich nicht von Kindern Instanz der test2()
zu nennen.
var c = new Child();
c.test2(); // c.test2 is not a function
Was ich falsch?
Für den Anfang wird 'this.prototype' in einem Konstruktor nicht tun, was Sie denken. Ich schlage vor, dass Sie ein Tutorial nachschlagen. –
[Wie Vererbung in JS Revealing Prototyp-Muster implementieren?] (Http://stackoverflow.com/questions/9248655/how-to-implement-inheritance-in-js-revealing-prototype-pattern) erläutert ausführlich wie Verwenden Sie das Modulmuster und die Vererbung. – Bergi