forked from RubyLouvre/mass-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.js
104 lines (100 loc) · 3.22 KB
/
class.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
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
102
103
104
define( "$class".split(","), function( $ ){
$.log("已加载text/class模块",7);
describe('class', {
"$.factory":function(){
var Ancestor = $.factory({
init:function(name){
this.name = name;
},
ancestor_prop:"3333333",
instance_fn:function(){
return "ancestor_instance"
},
instance_fn2:function(){
return "ancestor_instance2"
},
statics:{
class_fn:function(){
return "ancestor_class";
}
}
});
var Parent = $.factory(Ancestor, {
statics:{
class_fn:function(){
return "parent_class";
}
}
});
var Son = Parent.extend({
init:function(name,age){
this.age = age;
},
instance_fn2:function(){
return "son instance_fn2";
},
instance_fn3:function(){
return "instance_fn3"
},
statics:{
class_fn:function(){
return "son_class";
}
}
});
var p = new Parent("天空之城");
expect(p.instance_fn()).eq("ancestor_instance");
expect(Parent.class_fn()).eq("parent_class");
var s = new Son("司徒正美", 14);
expect(s.instance_fn()).eq("ancestor_instance");
expect(s.instance_fn2()).eq("son instance_fn2");
expect(Son.class_fn()).eq("son_class");
expect(s.ancestor_prop).eq("3333333");
expect(s.age).eq(14);
expect(s.name).eq("司徒正美");
var a = new Ancestor("时光之轮",30);
expect(a.age).eq(undefined);
expect(a.name).eq("时光之轮");
expect(s instanceof Parent).ok();
var VS = $.factory({
init:function(name){
this.name = name;
},
valueOf:function(){
return this.name+"111"
},
toString:function(){
return this.name+"222"
}
});
var v = new VS("小明");
expect(v.valueOf()).eq("小明111");
expect(v.toString()).eq("小明222");
v.setOptions("xxx",{
a: 111,
b: 222
});
expect(v.xxx.a ).eq(111);
expect(v.xxx.b ).eq(222);
v.setOptions({
c: 333,
d: 444
});
expect(v.c ).eq(333);
expect(v.d ).eq(444);
v.setOptions({
e: 555,
f: 666
},{
e: 777,
f: 888
},{
e: 999,
f: "yyy"
});
expect(v.e ).eq(999);
expect(v.f ).eq("yyy");
}
});
});
//2012.4.29 增加setOptions的测试