当前位置:网站首页>ES6对箭头函数的理解
ES6对箭头函数的理解
2022-08-02 00:14:00 【weixin_46051260】
1)箭头函数内的this指向是静态的,总是指向定义时所在的对象,而不是调用时,并且this指向是不可以改变的
2)this始终指向函数声明时所在作用域下的this的值
3)箭头函数不能当作构造函数,也就是不可以用new命令,否则报错
4)箭头函数不存在arguments对象,即不能使用伪数组去接受参数,可以使用rest参数代替
不适用场景:与this有关的回调,事件回调,对象方法回调
box.addEventListener('click',()=>{
console.log(this);//windows
})
使用场景:与this无关的回调,定时器,数组的方法回调
box.addEventListener('click',function(){
setTimeout(() => {
this.className='newBox'
}, 2000);
})
边栏推荐
猜你喜欢
什么是低代码(Low-Code)?低代码适用于哪些场景?
第 45 届ICPC亚洲区域赛(上海)G-Fibonacci
Quick solution for infix to suffix and prefix expressions
How to design a circular queue?Come and learn~
CVPR 2022 | SharpContour:一种基于轮廓变形 实现高效准确实例分割的边缘细化方法
Business test how to avoid missing?
MLX90640 红外热成像仪测温模块开发笔记(完整版)
c语言字符和字符串函数总结(二)
A simple file transfer tools
nodeJs--mime模块
随机推荐
链上治理为何如此重要,波卡Gov 2.0又会如何引领链上治理的发展?
JSP out.write()方法具有什么功能呢?
When Netflix's NFTs Forget Web2 Business Security
Unknown CMake command "add_action_files"
冒泡排序函数封装
CRS management and maintenance
Automatic conversion of Oracle-style implicit joins to ANSI JOINs using jOOQ
These 4 computer notepad software, you have to try
含外部储能的电力系统暂态稳定分布式控制
bgp aggregation reflector federation experiment
go语言标准库fmt包怎么使用
An overview of the most useful DeFi tools
C语言实现扫雷游戏
146. LRU cache
PHP从txt文件中读取数据的方法
Short video SEO search operation customer acquisition system function introduction
Redis的集群模式
MLX90640 红外热成像仪测温模块开发笔记(完整版)
Async/await principle and execution sequence analysis
Arduino Basic Syntax