-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
101 lines (96 loc) · 3.76 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>obajs</title>
<script src="oba.js"></script>
</head>
<body>
<a href="https://github.com/kmdjs/oba" target="_blank" style="position:absolute;right:0;top:0;">
<img src="http://alloyteam.github.io/AlloyGameEngine/AlloyPaper/example/asset/img/github.png" alt="" />
</a>
<p>open your browser's dev tool to compare the result.</p>
<div>
<div>expected result:</div>
<br/> c__2__33__#
<br/> c__2__33__#
<br/> b__4__undefined__#
<br/> c__33__2__#-1-a-1
<br/> Array-push__1,[object Object],3,4__1,[object Object],3__#
<br/> 3__5__4__#
<br/> Array-size__1,[object Object]__1,[object Object],3,5,5__#
<br/> d__100__4__#-c-0
<br/> b__[object Object]__2__#
<br/> a__3__2__#-b
<br/> 0__[object Object]__[object Object]__#-c
<br/> ccc__333__1__#-c-0
<br/> Array-push__[object Object],[object Object]__[object Object]__#-c
<br/> fff__3333__2__#-c-1
<br/> c__[object Object]__[object Object],[object Object]__#
<br/> e__111111111__5__#-c-0
<br/> name__wangwu__lisi__#
<br/> Array-push__11____#
<br/> Array-push__cccc____#
</div>
<script>
var obj = { a: 1 ,c:33};
//watch obj
oba(obj, function (name, value,old,path) {
console.log(name + "__" + value + "__" + old+"__"+path);
});
oba(obj,"c", function (name, value,old,path) {
console.log(name + "__" + value + "__" + old+"__"+path);
});
obj.c = 2;//twice==> c__2__33__#
oba.add(obj,"b",3);
obj.b = 4;//b__4__3__#
var arr = [1, {a:[1,{c:2},3]}, 3];
//watch array
oba(arr, function (name, value, old,path) {
console.log(name + "__" + value + "__" + old+"__"+path);
});
arr[1].a[1].c=33;//c__33__2__#-1-a-1
arr.push(4);//Array-push__1,[object Object],3,4__1,[object Object],3__#
arr[3] = 5;//3__5__4__#
//不建议下面,建议arr.push(5);
arr[4] = 5;
arr.size(2);//Array-size__1,[object Object]__1,[object Object],3,5,5__#
var complexObj = { a: 1, b: 2, c: [{ d: [4] }] };
//watch complexObj
oba(complexObj, function (name, value,old,path) {
console.log(name + "__" + value + "__" + old+"__"+path);
});
complexObj.c[0].d = 100; //d__100__4__#-c-0
complexObj.b={a:2};//b__[object Object]__2__#
complexObj.b.a=3;//a__3__2__#-b
complexObj.c[0]={ccc:1};//0__[object Object]__[object Object]__#-c
complexObj.c[0].ccc=333;//ccc__333__1__#-c-0
complexObj.c.push({fff:2});//Array-push__[object Object],[object Object]__[object Object]__#-c
complexObj.c[1].fff=3333;//fff__3333__2__#-c-1
complexObj.c=[{e:5}];//c__[object Object]__[object Object],[object Object]__#
complexObj.c[0].e=111111111;//e__111111111__5__#-c-0
var User = function (name, age) {
this.name = name;
this.age = age;
//watch User's instance
oba(this, ["name"], function (name, value, old,path) {
console.log(name + "__" + value + "__" + old+"__"+path);
});
};
var user = new User("lisi", 25);
user.name = "wangwu";//name__wangwu__lisi__#
user.age = 100;
var emptyArr = [];
oba(emptyArr, function (name, value, old, path) {
console.log(name + "__" + value + "__" + old + "__" + path);
});
emptyArr.push(11);
var emptyArr2 = {items:[]};
oba(emptyArr2, function (name, value, old, path) {
console.log(name + "__" + value + "__" + old + "__" + path);
});
emptyArr2.items.push("cccc");
//real push
emptyArr2.items.realPush("ddd");
</script>
</body>
</html>