class Parent{
private queueMap: Map<string, string> = new Map<string, string>();
private child : Child = new Child();
a () {
this.child.c(this.b);
}
b(){
console.log(this.queueMap);
}
}
class Child{
c(f : () => void){
f();
}
}
new Parent().a();
这是一段ts代码,可是为什么b()中的this为undefined呢,能不能在b()中获取到Parent对象呢?
可以用
绑定
this
。