作用域面试题
程序员文章站
2022-04-18 22:55:17
...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>04_作用域_面试题</title>
</head>
<body>
<script type="text/javascript">
var x = 10;
function fn() {
console.log(x);
}
function show(f) {
var x = 20;
f(); //10
}
show(fn);
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>04_作用域_面试题2</title>
</head>
<body>
<script type="text/javascript">
var fn = function () {
console.log(fn)
}
fn()
var obj = {
fn2: function () {
console.log(fn2) //报错
//console.log(this.fn2)
}
}
obj.fn2()
</script>
</body>
</html>
上一篇: cordova入门基础教程