55 lines
1.1 KiB
HTML
55 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
<script>
|
|
function f1() {
|
|
var n = 999;
|
|
// console.log(n)
|
|
function f11() {
|
|
console.log(n)
|
|
}
|
|
// f11()
|
|
return f11
|
|
}
|
|
|
|
var f2 = f1(); // =>f11
|
|
f2()
|
|
// 函数在没有return 语句或者是return 后面为空的时候, 函数的返回值等于undefined
|
|
// 如果return 后面不为空的话 那么函数的返回值 即等于 return后面的东西
|
|
|
|
// console.log(f2)
|
|
|
|
|
|
|
|
var name = "The Window";
|
|
|
|
var object = {
|
|
name: "My Object",
|
|
|
|
getNameFunc: function () {
|
|
var that = this;
|
|
return function () {
|
|
return that.name;
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
alert(object.getNameFunc()());
|
|
|
|
var func=object.getNameFunc()
|
|
func()
|
|
</script>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
</body>
|
|
|
|
</html> |