-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
39 lines (38 loc) · 946 Bytes
/
main.js
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
import Observer from './src/Observer.js';
let oberver = new Observer({
description:{
name:"Ysb",
job:"Front end developer",
favourites:['eating','reading']
}
})
//单个属性变化监听
observer.addWather(['name'],name=>{
console.log("name",name)
})
//多个属性变化监听
observer.addWather(['name','job'],(name,job)=>{
console.log("name,job",name,job)
}
//根据条件触发监听函数
observer.addWather(['favourites'],favourites=>{
console.log("favourites",favourites)
},function(newObserver,oldObserver,path){
return newObserver.length > 3
});
//更新监听的对象
observer.update({
name:"YSB",
job:"Front end developer",
favourites:['loving','eating','reading']
});
observer.update({
name:"YSB---",
job:"jser",
favourites:['loving','eating']
});
observer.update({
name:"YSB---",
job:"jser",
favourites:['loving','eating','woking','swimming']
});