-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex1.html
68 lines (68 loc) · 1.81 KB
/
index1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!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>
</head>
<body>
<h1>代码设计模式之代理模式</h1>
<script>
//陈美玲
//document.write('陈美玲')
//对象字面量,描述功能 表现力 一个花括号就是一个对象,key:value
//对象由属性和方法构成
//动作
let cml={
name:'小陈',
age:'20',
city:"于都",
// hasboyfriden:true,
isSingle:false,
hobby:"run",
//形参
sendFlower(o){
o.receiveFlower(this)
}
}
let xz={
xq:50,
name:"小张",
age:"20",
city:"南昌",
room:"201",
isSingle:true,
receiveFlower(o){
console.log(`${this.name}收到了${o.name}的花`)//打印 this指向当前的对象
if(this.xq>=90){
console.log("万达走一波。")
}
else{
console.log("酸辣汤准备好......")
}
}
}
//代理模式
let xe={
name:"小二",
age:"19",
room:"201",
city:"南昌",
//接口 当不同的对象,具有相同的方法时,可以互换使用
receiveFlower(o){
// if (o.name=="小陈"){
// console.log("让我们在一起吧...")
// }else{
//xz.receiveFlower(o)
//}
setTimeout(function(){
xz.xq=95;
xz.receiveFlower(o)
},10000)//定时器
}
}
cml.sendFlower(xe)
</script>
</body>
</html>