作为其他变量的值
<!DOCTYPE html>
<html lang="zh">
<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>
<script>
function foo(x, y) {
if (x > y) {
return x;
} else {
return y;
}
}
// 将 foo 函数作为变量 bar 的值
var bar = foo;
console.log(foo(12, 88))
console.log(bar(12, 66))
</script>
</body>
</html>
作为对象的属性值
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">