当前位置:网站首页>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);
})
边栏推荐
- 青蛙跳台阶
- 基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法
- PHP从txt文件中读取数据的方法
- 鲲鹏编译调试插件实战
- 具有通信时延的多自主体系统时变参考输入的平均一致性跟踪
- Play NFT summer: this collection of tools is worth collecting
- Realize deletion - a specified letter in a string, such as: the string "abcd", delete the "a" letter in it, the remaining "bcd", you can also pass multiple characters to be deleted, and pass "ab" can
- Redis 相关问题
- Grid false data injection attacks detection based on coding strategy
- Difference between JSP out.print() and out.write() methods
猜你喜欢

辨析内存函数memset、memcmp、memmove以及memcpy

【CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)(A~D)】

TCL: Pin Constraints Using the tcl Scripting Language in Quartus

BGP 第一次实验

How to design a circular queue?Come and learn~

Using the "stack" fast computing -- reverse polish expression

go笔记——map

渗透测试与攻防对抗——渗透测试基础

MLX90640 红外热成像仪测温传感器模块开发笔记(十) 成果展示-红眼睛相机

An interesting project--Folder comparison tool (1)
随机推荐
Arduino Basic Syntax
当奈飞的NFT忘记了Web2的业务安全
nodeJs--mime module
How to design a circular queue?Come and learn~
DFS详解
What does the errorPage attribute of the JSP page directive do?
TCL: Pin Constraints Using the tcl Scripting Language in Quartus
uni-app project summary
Graphical LeetCode - 1161. Maximum Sum of In-Layer Elements (Difficulty: Moderate)
BGP 第一次实验
JSP out. The write () method has what function?
PHP to read data from TXT file
已知中序遍历数组和先序遍历数组,返回后序遗历数组
Pytorch seq2seq 模型架构实现英译法任务
面试:简单介绍你参与的一个项目
MLX90640 红外热成像仪测温传感器模块开发笔记(十) 成果展示-红眼睛相机
JSP how to obtain the path information in the request object?
Task execution control in Ansible
uni-app项目总结
JSP out.write()方法具有什么功能呢?