0
我嘲讽User
和需要实现静态方法findOne
这是静态的,所以我不需要在我的呼唤类extensiate User
:如何从静态函数访问非静态属性的打字稿
export class User implements IUser {
constructor(public name: string, public password: string) {
this.name = 'n';
this.password = 'p';
}
static findOne(login: any, next:Function) {
if(this.name === login.name) //this points to function not to user
//code
return this; //this points to function not to user
}
}
但我无法从静态函数this
访问findOne
有没有在打字稿中使用它的方法?
一般来说,你不能从静态函数访问'this'。从类作用域调用静态函数,而从对象作用域调用成员函数。 –