定义:一段可执行的代码段,它作为一个参数传递给其他的代码,其作用是在需要的时候方便调用这段(回调函数)代码
//具名函数
function learn(some){
console.log(some)
}
function we(callback,something){
something+=' is cool'
callback(something)
}
we(learn,'Node.js')
effect:
![]()
//匿名函数
function we(callback,something){
something+=' is cool'
callback(something)
}
we(function(something){
console.log(something)
},'javascript')
effect:
![]()
本文介绍了JavaScript中回调函数的概念和使用方法,通过具名函数和匿名函数两种方式演示了回调函数的调用过程,展示了如何将回调函数作为参数传递并执行。
862

被折叠的 条评论
为什么被折叠?



