-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (37 loc) · 935 Bytes
/
index.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
var Module = require('module');
delete require.cache[module.id];
exports.class = function(path) {
return function() {
var _module = getUniqueModule(path);
//call constructor
if (_module.hasOwnProperty('constructor')) {
_module.constructor.apply(null, argumentsToArray(arguments));
}
return _module;
};
}
exports.extends = function(path) {
var baseClassObject = module.parent.exports;
var _module = getUniqueModule(path);
for (var property in _module) {
if (!baseClassObject.hasOwnProperty(property)) {
baseClassObject[property] = _module[property];
}
}
return _module;
}
function getUniqueModule(path) {
var parent = module.parent;
var filename = Module._resolveFilename(path, parent);
delete Module._cache[filename];
return Module._load(filename, parent);
}
function argumentsToArray(arg) {
var i = 0;
var arr = [];
while(arg.hasOwnProperty(i)) {
arr.push(arg[i]);
i++;
}
return arr;
}