Klass

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
function Klass(Parent, props) {
var Child, F, i;

// 新构造函数
Child = function(){
if (Child.uber && Child.uber.hasOwnProperty('__construct')) {
Child.uber.__construct.apply(this, arguments);
}

if (Child.prototype.hasOwnProperty('__construct')) {
Child.prototype.__construct.apply(this, arguments);
}
};

// 继承
Parent = Parent || Object;
F = function(){};
F.prototype = Parent.prototype;
Child.prototype = new F();
Child.uber = Parent.Prototype;
Child.prototype.constructor = Child;

// 添加实现方法
for (i in props) {
if (props.hasOwnProperty(i)){
Child.prototype[i] = props[i];
}
}

return Child;
}