When using the anti-shake function to pass parameters, the parameters will be stored in arguments.
Anti-shake function
/* 函数防抖 */
function debounce (fn, interval) {
let timer
const gapTime = interval || 1000 // 间隔时间,如果interval不传,则默认1000ms
return function () {
clearTimeout(timer)
const context = this
const args = arguments // 保存此处的arguments,因为setTimeout是全局的,arguments不是防抖函数需要的。
timer = setTimeout(function () {
fn.call(context, args)
}, gapTime)
}
}
use
const choseCityByName = utils.debounce((data) => {
console.log(data[0], data[1])
// 参数item为date[0], 参数index为data[1]
}, 200)
Passing on parameters
//参数会存储在防抖函数的arguments中
choseCityByName(item, index)