抱歉,如果这是一个重复的问题,我找不到...
我想写出一个属性,但仍然可以为空。
我要
public foo?: string;
成为(但可为空)
private _foo: string;
public get foo(): string {
return this._foo;
}
public set foo(v: string) {
// some logic with 'v'...
this._foo = v;
}
我应该把我的 ?
放在哪里?还是有别的办法?
我试过 Nullable<string>
但它也不起作用。
最佳答案
你可以写
private _foo: string|null;
public get foo(): string|null {
return this._foo;
}
public set foo(v: string|null) {
this._foo = v;
}
关于javascript - 如何编写可为空的完整属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56288734/