什么是回调函数?
如果将函数 A 作为参数传递给函数 B 时,我们称函数 A 为回调函数
常见使用场景:
function fn() {
console.log('我是回调函数...')
}
//fn 传递给了setInterval,fn就是回调函数
setInterval(fn, 1000)
使用匿名函数作为回调函数比较常见
如果将函数 A 作为参数传递给函数 B 时,我们称函数 A 为回调函数
function fn() {
console.log('我是回调函数...')
}
//fn 传递给了setInterval,fn就是回调函数
setInterval(fn, 1000)
使用匿名函数作为回调函数比较常见