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;
}());
我确实希望它被继承在我的情况下(不是静态的)...是的,这就是我一直在寻找的! –