@dexygen/

quickAndDirtyJsAOP

Nodejs

No description

fork
loading
Files
  • index.js
  • package-lock.json
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
const myModule = (function() {
  let result;
  const my = {
    setResult(x,y) {
      result = x + y;
    },
    getResult() {
      return result;
    }
  }
  return my;
})();

const predecessor = function() {
  console.log('arguments: ', arguments);
}

let precedableFns = {};

for (let fname in myModule) {
  if (/^set[A-Z]/.test(fname)) {
    precedableFns[fname] = myModule[fname];
    myModule[fname] = function() {
      predecessor.apply(this, arguments);
      precedableFns[fname].apply(this, arguments);
    }
  }
}

myModule.setResult(2,3);
console.log(myModule.getResult());

myModule.setResult(3,4);
console.log(myModule.getResult());
node v10.16.0