ひとり親クラスを続けたい。親クラスを継承するすべての clid クラスは、同じ親クラス オブジェクトを共有できます。それはどのように達成できますか?
var ParentClass = function(){
this.a = null;
}
ParentClass.prototype.setA = function(inp){
this.a = inp;
}
ParentClass.prototype.getA = function(){
console.log("get a "+this.a);
}
// Clild Class
var ClassB = function(){}
ClassB.prototype = Object.create(ParentClass.prototype);
var b = new ClassB();
b.setA(10);
b.getA(); //it will return 10
//Another clild Class
var ClassC = function(){}
ClassC.prototype = Object.create(ParentClass.prototype);
var c = new ClassC();
c.getA(); //I want 10 here.
2番目のclildクラスに関しては、親クラスが再びインスタンス化されているため、古いオブジェクトにアクセスできないことを理解しています。Javascriptでこのシングルトン継承を実現するにはどうすればよいですか? 何か案が?