classic.js
2.97 KB
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
// Generated by CoffeeScript 1.6.3
var classic,
__slice = [].slice;
module.exports = classic = {};
classic.implement = function() {
var classProto, classReference, desc, member, mixin, mixins, _i, _j, _len;
mixins = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), classReference = arguments[_i++];
for (_j = 0, _len = mixins.length; _j < _len; _j++) {
mixin = mixins[_j];
classProto = classReference.prototype;
for (member in mixin.prototype) {
if (!Object.getOwnPropertyDescriptor(classProto, member)) {
desc = Object.getOwnPropertyDescriptor(mixin.prototype, member);
Object.defineProperty(classProto, member, desc);
}
}
}
return classReference;
};
classic.mix = function() {
var classProto, classReference, desc, member, mixin, mixins, _i, _j, _len;
mixins = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), classReference = arguments[_i++];
classProto = classReference.prototype;
classReference.__mixinCloners = [];
classReference.__applyClonersFor = function(instance, args) {
var cloner, _j, _len, _ref;
if (args == null) {
args = null;
}
_ref = classReference.__mixinCloners;
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
cloner = _ref[_j];
cloner.apply(instance, args);
}
};
classReference.__mixinInitializers = [];
classReference.__initMixinsFor = function(instance, args) {
var initializer, _j, _len, _ref;
if (args == null) {
args = null;
}
_ref = classReference.__mixinInitializers;
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
initializer = _ref[_j];
initializer.apply(instance, args);
}
};
classReference.__mixinQuitters = [];
classReference.__applyQuittersFor = function(instance, args) {
var quitter, _j, _len, _ref;
if (args == null) {
args = null;
}
_ref = classReference.__mixinQuitters;
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
quitter = _ref[_j];
quitter.apply(instance, args);
}
};
for (_j = 0, _len = mixins.length; _j < _len; _j++) {
mixin = mixins[_j];
if (!(mixin.constructor instanceof Function)) {
throw Error("Mixin should be a function");
}
for (member in mixin.prototype) {
if (member.substr(0, 11) === '__initMixin') {
classReference.__mixinInitializers.push(mixin.prototype[member]);
continue;
} else if (member.substr(0, 11) === '__clonerFor') {
classReference.__mixinCloners.push(mixin.prototype[member]);
continue;
} else if (member.substr(0, 12) === '__quitterFor') {
classReference.__mixinQuitters.push(mixin.prototype[member]);
continue;
}
if (!Object.getOwnPropertyDescriptor(classProto, member)) {
desc = Object.getOwnPropertyDescriptor(mixin.prototype, member);
Object.defineProperty(classProto, member, desc);
}
}
}
return classReference;
};