class Greeter {
static standardGreeting = 'Hello, there'
greeting: string
constructor(message?: string) {
this.greeting = message
}
greet() {
if (this.greeting) {
return 'Hello, ' + this.greeting
} else {
return Greeter.standardGreeting
}
}
}
let greeter: Greeter
greeter = new Greeter()
console.log(greeter.greet())
let greeterMaker: typeof Greeter = Greeter
greeterMaker.standardGreeting = 'Hey there'
let greeter2: Greeter = new greeterMaker()
console.log(greeter2.greet())
"Greeter 是实例类型,typeof Greeter 就是类类型"
按对这句话的理解:
greeter的类型是Greeter的实例类型,那它的值只要包含’class Greeter’的实例部分即可?
greeterMaker的类型是Greeter的类类型,那它的值只要包含’class Greeter’静态部分即可?