has*_*ram 0 javascript this ecmascript-6
function Person(){
this.age = 0;
setInterval(() => {
this.age++; // this refers to the person object
}, 1000);
}
Run Code Online (Sandbox Code Playgroud)
但是如果我想访问setInterval函数的"this"而不是父对象呢?我知道箭头的功能没有词法这个属于自己的,但有什么办法来规避这一点,除了写一个非箭头功能?
| 归档时间: |
|
| 查看次数: |
226 次 |
| 最近记录: |