-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcla55.js
149 lines (116 loc) · 4.69 KB
/
cla55.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
/*jscs:disable disallowDanglingUnderscores*/
/*global require, exports, module, define*/
(function (root, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// AMD: Register as an anonymous module
return define(['require', 'exports', 'module'], factory);
}
if (typeof exports === 'object') {
// CommonJS
return factory(require, exports, module);
}
}(this, function (require, exports, module) {
'use strict';
var Cla55, assign, hook;
assign = function assign(target, source) {
var key;
for (key in source) {
if (source.hasOwnProperty(key)) {
target[key] = source[key];
}
}
return target;
};
// Hook prototype methods with _super() and _superApply()
hook = function hook(parentProto, childProto, protoProps) {
var hookProp = function hookProp(prop, value) {
if (typeof protoProps[prop] === 'function' && typeof parentProto[prop] === 'function') {
childProto[prop] = (function () {
var _super = function () {
return parentProto[prop].apply(this, arguments);
},
_superApply = function (args) {
return parentProto[prop].apply(this, args);
};
return function () {
var __super = this._super,
__superApply = this._superApply,
returnValue;
this._super = _super;
this._superApply = _superApply;
returnValue = protoProps[prop].apply(this, arguments);
this._super = __super;
this._superApply = __superApply;
return returnValue;
};
}());
} else {
childProto[prop] = protoProps[prop];
}
},
key;
for (key in protoProps) {
if (protoProps.hasOwnProperty(key)) {
hookProp(key);
}
}
};
Cla55 = function Cla55() {
return this.constructor.apply(this, arguments);
};
Cla55.prototype.constructor = function Cla55() {
return;
};
Cla55.extend = function extend(protoProps, staticProps, _super) {
// Ensure prototype and static are define objects
protoProps = protoProps || (protoProps = {});
staticProps = staticProps || (staticProps = {});
var Parent = this,
Child = function Cla55() {
if (this instanceof Child) {
// Call the instance constructor
return this.constructor.apply(this, arguments);
} else {
// Static call of the constructor
return Child.prototype.constructor.apply(Child, arguments);
}
},
Surrogate = function Cla55() {
return;
};
// Set the prototype chain to inherit from `parent`
Surrogate.prototype = Parent.prototype;
Child.prototype = new Surrogate();
// Clear prototype reference
Surrogate.prototype = null;
// Assign parent static properties to the new class
assign(Child, Parent);
// Ensure new class has static extend method
assign(Child, !Child.extend ? {extend: Cla55.extend} : {});
// Assign provided static properties to the new class
assign(Child, staticProps);
// Set a constructor on the new prototype
if (protoProps.hasOwnProperty('constructor')) {
protoProps.constructor = protoProps.constructor;
} else if (Parent.prototype.hasOwnProperty('constructor')) {
protoProps.constructor = Parent.prototype.constructor;
} else {
protoProps.constructor = Parent;
}
// Assign provided prototype properties to the new class
if (_super === true) {
hook(Parent.prototype, Child.prototype, protoProps);
} else {
assign(Child.prototype, protoProps);
}
return Child;
};
exports.Cla55 = Cla55;
exports.extend = function (protoProps, staticProps, _super) {
return exports.Cla55.extend.call(exports.Cla55, protoProps, staticProps, _super);
};
exports.create = function cla55(Parent, protoProps, staticProps, _super) {
return exports.Cla55.extend.call(Parent, protoProps, staticProps, _super);
};
}));