function Person(){
this.age = 0;
setInterval(() => {
this.age++; // this refers to the person object
}, 1000);
}
但是如果我想访问 setInterval 函数的“this”而不是父对象怎么办?我知道箭头函数没有自己的词法 this,但是除了编写非箭头函数之外,还有其他方法可以绕过它吗?
最佳答案
Is there a way to circumvent this, other than writing a non-arrow function?
没有。
传递给箭头函数的 this 值会被它忽略,并且不能以任何形式使用。
关于javascript - ES6 箭头函数可以有自己的词法 this 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48988017/