()=>{}和function(){}有区别吗
时间: 2024-06-12 22:04:37 浏览: 4
没有本质区别。
`()=>{}`是ES6中的箭头函数写法,而`function(){}`是传统的函数写法。两种写法都可以创建一个函数。
但是,箭头函数和传统函数在一些方面有所不同。
1. 箭头函数没有自己的this,它的this指向定义它时所在的上下文。
2. 箭头函数没有arguments对象。
3. 箭头函数不能用作构造函数。
4. 箭头函数更简洁,可以省略return关键字(如果只有一条语句)。
所以,虽然两种写法都可以创建函数,但在一些特殊情况下,箭头函数和传统函数的行为可能会有所不同。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)