例如,如果我有这个类(class):
type Url: string;
class A {
#url: Url
}
#
符号的作用/代表什么?谢谢!
最佳答案
这是一个ECMAScript private field ,TypeScript 3.8 中的新增功能。该字段可以从类内部的方法访问,但不能从类外部访问。
更多信息:
文档中的示例:
class Animal { #name: string; constructor(theName: string) { this.#name = theName; } } new Animal("Cat").#name; // Property '#name' is not accessible outside class 'Animal' because it has a private identifier.
关于typescript - TypeScript 类中的 # 符号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60961043/