前端学习日记(十三)
一.课程学习
改变this指向
bind
不会调用函数,而是创建一个指定了this值的新函数
// 普通函数 function sayHi() { console.log(this) } let user = { name: \'小明\', age: 18 } // 调用 bind 指定 this 的值 let sayHello = sayHi.bind(user); // 调用使用 bind 创建的新函数 sayHello()
防抖
指触发事件后在 n 秒内函数只能执行一次,如果在 n 秒内又触发了事件,则会重新计算函数执行时间
节流
指连续触发事件但是在 n 秒中只执行一次函数