记 ()=>{}箭头函数的使用
2021/11/30 23:07:22
本文主要是介绍记 ()=>{}箭头函数的使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
let foo3 = function() { console.log('hahawoshi foo3') } foo3(); let foo4 = () => { console.log('haha woshi foo4') } foo4(); //箭头函数this 是静态的,this始终指向函数声明时所在的作用域下的this 的值 //call 能改变this的指向 function getName() { console.log(this.name); } let getName2 = () => { console.log(this.name); } window.name = '哈哈'; let people = { name: '张三', age : 18 } getName();//哈哈 getName2();//哈哈 getName.call(people);//张三 普通函数 this指向当前声明的函数 getName2.call(people);//哈哈 箭头函数 this 指向函数声明时所在作用域下的this的值 2.不能作为构造实例化对象 3.不能使用arguments变量
let f = () => {
console.log(arguments);
}
f(1);//报错
let f2 = function() {
console.log(arguments);
}
f2(1);//arguments...
let arrx = [1,66,54,78,66,3,1]
const res5 = arrx.filter(function(item) {
if(item % 2 === 0) {
return true;
} else {
return false;
}
})
res6 = arrx.filter(item => {
if(item%2===0) {
return true;
} else {
return false;
}
})
res6 = arrx.filter(item => item % 2 ===0)
console.log(res6,'res6');
箭头函数适合与this 无关的回调,定时器,数组的方法回调
箭头函数不适合与this 有关的回调,事件回调
这篇关于记 ()=>{}箭头函数的使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-06小米11i印度快充版ROM合集:极致体验,超越期待
- 2024-10-06【ROM下载】小米11i 5G 印度版系统, 疾速跃迁,定义新速度
- 2024-10-06【ROM下载】小米 11 青春活力版,青春无极限,活力全开
- 2024-10-05小米13T Pro系统合集:性能与摄影的极致融合,值得你升级的系统ROM
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求