javascript oop で node.js 構造に問題があります。別のクラスを使用してクラスを作成しました。
var base = function (name) {
this.Rows = new Array();
};
var top = function (name) {
this.name = name;
};
top.prototype = new base();
var myClass = new top("");
myClass.Rows.push("a");
console.log(myClass.Rows);
var myClass2 = new top("test");
myClass2.Rows.push("b");
console.log(myClass2.Rows);
このコードは次の結果を返します。
[ 'a' ]
[ 'a', 'b' ]
しかし、このコードの結果としてアルゴリズムによって検出される必要はありませんか?
[ 'a' ]
[ 'b' ]
助けてくれてありがとう。
解決済み: この問題を解決しました。コードのリファクタリング;
var base = function (name) {
this.Rows = new Array();
}
var top = function(name) {
top.prototype.constructor.call(this, name);
this.name = name;
}
top.prototype = Object.create(new base());
全てに感謝。