-
Notifications
You must be signed in to change notification settings - Fork 0
/
classtrophobic-es5.js
161 lines (161 loc) · 5.44 KB
/
classtrophobic-es5.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*! (C) 2017 Andrea Giammarchi - MIT Style License */
var Class = (function (Object) {'use strict';
var
reserved = ['constructor', 'extends', 'static'],
isNative = function (fn) {
return /\[native code\]/.test(Object.toString.call(fn));
},
ObjectProto = Object.prototype,
gPO = Object.getPrototypeOf ||
function (o) { return o.__proto__; },
sPO = Object.setPrototypeOf ||
function (o, p) { o.__proto__ = p; return o; },
gOPD = Object.getOwnPropertyDescriptor,
defineProperty = Object.defineProperty,
defProps = Object.defineProperties,
hasReflect = typeof Reflect === 'object',
construct = hasReflect &&
Reflect.construct ||
function (Super, args, Constructor) {
[].unshift.call(args, Super);
var C = Super.bind.apply(Super, args);
return sPO(new C, Constructor.prototype);
},
ownKeys = hasReflect &&
Reflect.ownKeys ||
(Object.getOwnPropertySymbols ?
function ownKeys(o) {
return Object.getOwnPropertySymbols(o)
.concat(Object.getOwnPropertyNames(o));
} :
Object.getOwnPropertyNames),
superPropertyDescriptor = {
get: function () {
var
Super = function () {
var
constructor = self.constructor,
parent = gPO(proto),
result
;
sPO(self, parent);
while ((parent.constructor === constructor)) parent = gPO(parent);
self.constructor = constructor;
try {
result = isNative(parent.constructor) ?
construct(parent.constructor, arguments, constructor) :
parent.constructor.apply(self, arguments);
} finally {
sPO(self, proto);
}
delete self.constructor;
return result ? sPO(result, proto) : self;
},
self = this,
proto = gPO(self),
parent = proto,
call = Super.call,
apply = Super.apply
;
if (proto) {
sPO(Super, proto);
Super.call = call;
Super.apply = apply;
do {
ownKeys(parent).forEach(function (prop) {
if (Super.hasOwnProperty(prop)) return;
var
descriptor = gOPD(parent, prop),
method = descriptor.value
;
if (typeof method === 'function') {
descriptor.value = function () {
var result, parent = proto;
do { parent = gPO(parent); }
while ((method === parent[prop]));
try { result = parent[prop].apply(sPO(self, parent), arguments); }
finally { sPO(self, proto); }
return result;
};
defineProperty(Super, prop, descriptor);
}
});
} while ((parent = gPO(parent)) && parent !== ObjectProto);
}
return Super;
}
},
superStaticDescriptor = {
get: function () {
var Super = {}, self = this, parent = self;
do {
ownKeys(parent).forEach(function (prop) {
var
descriptor = gOPD(parent, prop),
method = descriptor.value
;
if (typeof method === 'function') {
descriptor.value = function () {
var
proto = gPO(self), method = self[prop],
result, parent = proto
;
while ((method === parent[prop])) parent = gPO(parent);
self.method = parent[prop];
try { result = self.method.apply(sPO(self, gPO(parent)), arguments); }
finally { sPO(self, proto).method = method; }
return result;
};
defineProperty(Super, prop, descriptor);
}
});
} while((parent = gPO(parent)) && parent !== Function);
return Super;
}
}
;
return function Classtrophobic(definition) {
var
Constructor = definition.constructor,
Statics = definition['static'],
Super = definition['extends'],
Class = definition.hasOwnProperty('constructor') ?
function () {
return Constructor.apply(this, arguments) || this;
} :
(Super ?
(isNative(Super) ?
function () {
return construct(Super, arguments, Class);
} :
function () {
var result = Super.apply(this, arguments);
return result ? sPO(result, Class.prototype) : this;
}
) :
function () {}
),
Static = {'super': superStaticDescriptor},
Prototype = {'super': superPropertyDescriptor}
;
if (Super) {
sPO(Class, Super);
sPO(Class.prototype, Super.prototype);
}
ownKeys(definition)
.forEach(function (key) {
if (reserved.indexOf(key) < 0) {
Prototype[key] = gOPD(definition, key);
Prototype[key].enumerable = false;
}
});
defProps(Class.prototype, Prototype);
if (Statics) ownKeys(Statics).forEach(function (key) {
Static[key] = gOPD(Statics, key);
Static[key].enumerable = false;
});
Class.prototype.constructor = Class;
return defProps(Class, Static);
};
})(Object);
try { module.exports = Class; } catch(o_O) {}