点击运行
class Employee { first: string; last: string; constructor(first: string, last: string) { this.first = first; this.last = last; } getFullNameFunction() { return () => { console.log(this); // 现在 this 是 Employee 的实例 return this.first + ' ' + this.last; }; } } const e1 = new Employee('John', 'Doe'); const func = e1.getFullNameFunction(); console.log(func()); // "John Doe"
运行结果 :
正在执行...