-
Notifications
You must be signed in to change notification settings - Fork 3
/
leta.class.js
84 lines (65 loc) · 2.22 KB
/
leta.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
/**
* Leta.Class
*/
(function (win, undefined) {
var context = this,
L = this['Leta'],
$name = L['$name'],
fnTest = /leta/.test(function () { leta }) ? /\b_super\b/ : /.*/,
isFunction = function (o) {
return (L.toType(o) == 'function' && o.apply && o.call);
};
function Class (o) {
return extend.call(isFunction(o) ? o : function () {}, o, 1);
}
function process (target, o, _super) {
for (var k in o) {
if (o.hasOwnProperty(k)) {
target[k] = (isFunction(o[k]) && isFunction(_super.prototype[k]) && fnTest.test(o[k])) ? wrap(k, o[k], _super) : o[k];
}
}
}
function wrap (k, fn, _super) {
return function () {
var tmp = this._super;
this._super = _super.prototype[k];
var ret = fn.apply(this, arguments);
this._super = tmp;
return ret;
}
}
function extend (o, fromSub) {
function superClass () {}
superClass.prototype = this.prototype;
var _super = this,
prototype = new superClass(),
_constructor = isFunction(o) ? o : this,
_methods = isFunction(o) ? {} : o;
function classFn () {
if (!!this.initialize) {
this.initialize.apply(this, arguments);
} else {
!!fromSub || isFunction(o) && _super.apply(this, arguments);
_constructor.apply(this, arguments);
}
}
classFn.methods = function (o) {
process(prototype, o, _super);
classFn.prototype = prototype;
return this;
};
classFn.methods.call(classFn, _methods).prototype.constructor = classFn;
classFn.extend = arguments.callee;
classFn.prototype.implement = Class.statics = function (o, optFn) {
o = L.toType(o) === 'string' ? (function () {
var obj = {};
obj[o] = optFn;
return obj;
}()) : o;
process(this, o, _super);
return this;
}
return classFn;
}
Leta.extend({Class: Class});
})(window);