JavaScript でプライベート メンバーを基本クラスからサブクラスに継承する方法はありますか?
私はこのようなことを達成したい:
function BaseClass() {
var privateProperty = "private";
this.publicProperty = "public";
}
SubClass.prototype = new BaseClass();
SubClass.prototype.constructor = SubClass;
function SubClass() {
alert( this.publicProperty ); // This works perfectly well
alert( this.privateProperty ); // This doesn't work, because the property is not inherited
}
プライベート (保護された) プロパティを継承できる他の oop 言語 (C++ など) のように、クラスのようなシミュレーションを実現するにはどうすればよいですか?
ありがとう、デビッド・シュライバー