箭头函数 this指向
时间: 2023-09-04 22:14:20 浏览: 123
箭头函数的this指向是继承而来的,并且指向在定义它时所处的对象,即父级作用域,而不是执行时的对象。这意味着箭头函数内部的this的值不会受到函数调用方式的影响,而是固定指向外层代码块的this。这种特性让箭头函数在使用setTimeout、setInterval等场景下更加方便地使用this。所以,无论箭头函数在哪里被调用,它的this都指向定义它的外层代码块的this,而不是调用时的对象。这与传统的函数的运行机制不同,传统的函数中的this是动态绑定的,它的值会根据函数的调用方式来决定。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [箭头函数this的指向](https://blog.csdn.net/weixin_57959921/article/details/129439200)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [关于箭头函数中的this的指向](https://blog.csdn.net/xu4321083/article/details/79753800)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [箭头函数及其this的指向](https://blog.csdn.net/qq_53841687/article/details/125770647)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文