-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase-object.js
31 lines (26 loc) · 975 Bytes
/
base-object.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
'use strict';
function BaseObject() {}
BaseObject.prototype.init = function() {};
BaseObject.prototype.extend = BaseObject.extend = function(obj) {
var instance = new BaseObject();
for (var k in obj) {
if (!obj.hasOwnProperty(k)) {
continue;
}
if (this.hasOwnProperty(k) && typeof obj[k] === 'function') {
var base = this[k];
instance[k] = obj[k];
instance[k]._base = base;
} else {
instance[k] = obj[k];
}
}
return function() {
instance.init.apply(instance, arguments);
return instance;
};
};
/* global define:true module:true window: true */
if (typeof define === 'function' && define['amd']) { define(function() { return BaseObject; }); }
if (typeof module !== 'undefined' && module['exports']) { module['exports'] = BaseObject; }
if (typeof window !== 'undefined') { window['BaseObject'] = BaseObject; }