forked from fullcalendar/fullcalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Class.js
40 lines (30 loc) · 1.22 KB
/
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
fc.Class = Class; // export
// class that all other classes will inherit from
function Class() { }
// called upon a class to create a subclass
Class.extend = function(members) {
var superClass = this;
var subClass;
members = members || {};
// ensure a constructor for the subclass, forwarding all arguments to the super-constructor if it doesn't exist
if (hasOwnProp(members, 'constructor')) {
subClass = members.constructor;
}
if (typeof subClass !== 'function') {
subClass = members.constructor = function() {
superClass.apply(this, arguments);
};
}
// build the base prototype for the subclass, which is an new object chained to the superclass's prototype
subClass.prototype = createObject(superClass.prototype);
// copy each member variable/method onto the the subclass's prototype
copyOwnProps(members, subClass.prototype);
// copy over all class variables/methods to the subclass, such as `extend` and `mixin`
copyOwnProps(superClass, subClass);
return subClass;
};
// adds new member variables/methods to the class's prototype.
// can be called with another class, or a plain object hash containing new members.
Class.mixin = function(members) {
copyOwnProps(members.prototype || members, this.prototype);
};