class Test {
constructor() {
console.log("Test constructor")
}
instance() {
console.log("我是实例方法")
}
static a(x: string) {
console.log(x)
}
static b(x: string) {
/**
* 1、静态方法中的this指向的是当前类
*/
new this().instance()
console.log(this)
this.a("Test.a")
console.log(x)
}
}
class Test01 extends Test {
}
Test01.b("Test01.b")
【Typescript】Js或Ts的静态方法中的this就是指向当前类,实例方法中的this执行当前实例
最新推荐文章于 2024-04-29 17:54:33 发布