<script>
// 需求1 点击 div 2s后颜色变成 粉色
// 获取元素
let ad = document.getElementById('ad');
// 绑定事件
ad.addEventListener("click",function(){
// 保存this的值
// let _this = this; 之前的解决方案
// 定时器
//setTimeout(function(){
// 修改背景颜色 this
// 之前的写法_this.style.background = 'pink';
//},2000);
// 变成箭头函数之后
setTimeout(()=>{
this.style.background = 'pink';
},2000);
})
// 需求2 从数组中返回偶数的元素
const arr = [1,6,9,10,100,25];
// const result = arr.filter(function(item){
// if(item % 2 ===0){
// return true;
// }else{
// return false;
// }
// });
// 使用箭头函数
const result = arr.filter(item => item % 2 === 0);
console.log(result);
// 箭头函数 适合与 this 无关的回调 定时器 数组的方法回调
// 箭头函数不适合与this有关的回调 事件回调 对象的方法
</script>
es6
生活的强者,不是指能搞定一切困难,也不是指没有恐惧,而是就算心里藏着无尽的疲惫和委屈,还是会认真地做好手头上的事情;就算自己被生活锤得心灰意冷,还是会尽心尽力地负起责任;就算发现现实与理想的差距有十万里,虽然鞭长莫及,却依然马不停蹄。