0
点赞
收藏
分享

微信扫一扫

JavaScript-函数作为参数和返回值

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

<!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>




举报

相关推荐

0 条评论