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;
}());
我確實希望它被繼承在我的情況下(不是靜態的)...是的,這就是我一直在尋找的! –