-
Notifications
You must be signed in to change notification settings - Fork 1
/
oo.js
43 lines (43 loc) · 1.57 KB
/
oo.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
(function(Class){
var base, ctor, extend, inherits, root = this;
base = function(){
this.initialize.apply(this, arguments);
};
base.prototype = {
initialize: function(){}
}
base.extend = function (protoProps, classProps) {
var child = inherits(this, protoProps, classProps);
child.extend = this.extend;
return child;
};
extend = function(obj, source) {
for (var prop in source) {
if (source.hasOwnProperty(prop)) {
var objProp = obj[prop], sourceProp = source[prop], object = '[object Object]';
if (toString.call(objProp) === object && toString.call(sourceProp) === object) {
extend(objProp, sourceProp);
}
else {
if (typeof sourceProp === 'function') {
sourceProp.__name__ = prop;
}
obj[prop] = sourceProp;
}
}
}
};
ctor = function(){};
inherits = function(parent, protoProps, classProps) {
var child = protoProps && protoProps.hasOwnProperty('constructor') ? protoProps.constructor
: function(){ return parent.apply(this, arguments) };
extend(child, parent);
ctor.prototype = child.__super__ = parent.prototype;
child.prototype = new ctor;
protoProps && extend(child.prototype, protoProps);
classProps && extend(child, classProps);
child.prototype.constructor = child;
return child;
};
root[Class] = base;
})('Class');