将函数作为其他函数的参数。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Demo</title>
    <script type="text/javascript">
        let say = function () {
            console.log("hello world");
        }

        say();

        let temp = say;
        temp();

        //  let fn = say;
        function test(fn) {
            fn();
        }

        test(say);
    </script>
</head>
<body>
</body>
</html>

将函数作为其他函数的返回值。????注意点:在其它编程语言中函数是不可以嵌套定义的,但是在 JavaScript 中函数是可以嵌套定义的。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Demo</title>
    <script type="text/javascript">
        function test() {
            return function () {
                console.log("hello world");
            }
        }

        let fn = test();
        fn();
    </script>
</head>
<body>
</body>
</html>

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2021-12-12
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-27
  • 2022-12-23
  • 2021-09-23
相关资源
相似解决方案