关于arguments的问题
来源:16-9 手写节流 throttle

光天化日之下
2020-01-08
setTimeout里面为什么用箭头函数 arguments才生效,用function () {} 就会报错
index.js:35 Uncaught TypeError: Cannot read property ‘offsetX’ of undefined
function throttle (func, wait = 100) {
var timer = null
return function () {
if (timer) {
return
}
timer = setTimeout(function () {
// 这里如果不用箭头函数,arguments不起作用
func.apply(this, arguments)
timer = null
}, wait)
}
}
写回答
1回答
-
针对箭头函数和 function 两种情况,你分别打印一下 arguments 的值,看输出什么。
012020-01-08
相似问题