<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
function demo1() {
return 'demo1';
}
function demo2() {
return 'demo2';
}
function demo3(title) {
return title;
}
function test1(fun) {
console.log('test1')
if (fun) {
let result = fun();
console.log(result);
}
}
function test2(fun, param) {
console.log('test2')
if (fun) {
let result = fun(param);
return result;
}
}
// 方法作为参数传递
// 调用无参数方法
test1(demo1);
test1(demo2);
// 调用有参数方法
let result = test2(demo3, 'hello world!')
console.log(result);
</script>
</head>
<body>
</body>
</html>
js将函数作为参数传入
最新推荐文章于 2023-07-19 21:03:24 发布