<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<script>
//函数的上下文有调用的方式来决定
//规则1 题1
//对象.方法();
function fun() {
console.log(this.a + this.b);
}
var obj = {
a: 11,
b: 22,
c: fun
}
obj.c(); //33
//规则1 题2
var obj1 = {
a: 1,
b: 2,
c: function() {
console.log(this.a + this.b);
}
}
var obj2 = {
a: 11,
b: 22,
c: obj1.c
}
obj2.c();
//规则3 题3
function fun1() {
var a = 1;
var b = 2;
return {
a: 11,
b: 22,
c: function() {
console.log(this.a + this.b);
}
}
}
fun1().c(); //33
</script>
</body>
</html>