-
Notifications
You must be signed in to change notification settings - Fork 4
/
oop.js
54 lines (50 loc) · 1.55 KB
/
oop.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
/**
* using AMD (Asynchronous Module Definition) API with OzJS
* see http://ozjs.org for details
*
* Copyright (C) 2010-2012, Dexter.Yy, MIT License
* vim: et:ts=4:sw=4:sts=4
*/
define("mo/lang/oop", [
"./es5",
"./mix"
], function(es5, _, require, exports){
var mix = _.mix;
function _apply(base, self, args){
return base.apply(self, args);
}
exports.construct = function(base, mixes, factory){
if (mixes && !Array.isArray(mixes)) {
factory = mixes;
}
if (!factory) {
factory = function(){
this.superConstructor.apply(this, arguments);
};
}
var proto = Object.create(base.prototype),
supr = Object.create(base.prototype),
constructor = function(){
var self = this;
this.constructor = constructor;
this.superConstructor = function(){
_apply.prototype = base.prototype;
var su = new _apply(base, self, arguments);
for (var i in su) {
if (!self[i]) {
self[i] = supr[i] = su[i];
}
}
};
this.superClass = supr;
return factory.apply(this, arguments);
};
constructor.prototype = proto;
if (mixes) {
mixes = mix.apply(this, mixes);
mix(proto, mixes);
mix(supr, mixes);
}
return constructor;
};
});