-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.js
More file actions
49 lines (39 loc) · 1.17 KB
/
class.js
File metadata and controls
49 lines (39 loc) · 1.17 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
/**
* Class.js
* JavaScript inheritance
* (c) 2013 Ilya Igonkin
* Licensed under the MIT license
*/
(function(window, undefined) {
var Class = window.Class = function() {};
var has = Object.prototype.hasOwnProperty;
Class.inherit = function(Parent, protoProps) {
var Child = (protoProps && has.call(protoProps, 'constructor'))
? protoProps.constructor
: function() { return Parent.apply(this, arguments); };
for (var property in Parent) {
if (has.call(Parent, property)) {
Child[property] = Parent[property];
}
}
var SubClass = function() {};
SubClass.prototype = Parent.prototype;
Child.prototype = new SubClass();
for (var property in protoProps) {
Child.prototype[property] = protoProps[property];
}
Child.prototype.__super__ = Parent.prototype;
Child.prototype.constructor = Child;
return Child;
};
Class.extend = function(protoProps) {
return this.inherit(this, protoProps);
};
Class.include = function(staticProps) {
for (var property in staticProps) {
if (has.call(staticProps, property)) {
this[property] = staticProps[property];
}
}
};
})(this);