0
文字列フィールドを持つクラスを作成すると、常にコンストラクタの割り当てに移行します。インスタンスごとに新しい文字列の代わりに共有するように、プロトタイプにすることは可能ですか?TypeScriptでクラスのプロトタイプに文字列を作成する方法
class A {
a = 'hello'
b() { return this.a;}
}
// Transpiles into
var A = (function() {
function A() {
this.a = 'hello';
}
A.prototype.b = function() { return this.a; };
return A;
}());
// Is it possible to make it go on the prototype like functions do?
// No need for multiple instances of the string
var A = (function() {
function A() {}
A.prototype.b = function() { return this.a; };
A.prototype.a = 'hello';
return A;
}());
私はそれが私の場合(静的ではない)に継承されて欲しいです...はい、これは私が探していたものです! –