-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
26 lines (20 loc) · 816 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
function classHooks(classObject, wrap, whiteList) {
const classHandler = {
construct(Target, argumentsList, newTarget) {
const instance = new Target(...argumentsList);
const instanceHandler = {
get(target, property, receiver) {
const functionWrapper = function(...args) {
return wrap.call(receiver, instance, target[property], args);
};
return !whiteList || (whiteList && whiteList.includes(property)) ?
functionWrapper :
target[property];
}
};
return new Proxy(instance, instanceHandler);
}
};
return new Proxy(classObject, classHandler);
}
module.exports = classHooks;