回调函数

Posted yangxiaohui227

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了回调函数相关的知识,希望对你有一定的参考价值。

回调函数的定义:一个函数的参数是另一个函数,那么作为参数的函数就是一个回调函数,例如定时器中的参数:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>

function a(){}
function c(fn){
    fn(); //此时fn就是回调函数
}

c(a);//调用函数
var timerId=setInterval(function(){},1000);//定时器第第一个参数就是回调函数


</script>

 

以上是关于回调函数的主要内容,如果未能解决你的问题,请参考以下文章