title: How to use Proxy to intercept every function of an object in JavaScript or E6?
body: <p>I have a class A, defined like below.(All sample code is simplified for privacy)</p>
  
  <pre><code> class A{
       Func1(){
  
      } 
      Func2(){
  
      }
      Func3(){
  
      }
   }
  </code></pre>
  
  <p>And I want to make every function in A running after another function Func4();
  So I write a fuction to intercept through Proxy like below:</p>
  
  <pre><code>   _Intercept(object) {
          if (object === undefined || object === null) {
              throw new Error('intercept need non null object');
          }
  
          const objectPrototypes = Object.getPrototypeOf(object);
          const objectPropertyNames = Object.getOwnPropertyNames(objectPrototypes);
          for (const index in objectPropertyNames) {
              const protoName = objectPropertyNames[index];
  
              if (!object.__proto__.hasOwnProperty(protoName)) {
  
                  continue;
  
              }
  
              let originalFunction = object.__proto__[protoName];
              if (originalFunction === undefined || originalFunction === null) {
  
                  continue;
              }
  
              if (typeof (originalFunction) !== 'function') {
  
                  continue;
              }
              if (protoName === 'constructor') {
  
                  continue;
              }
              console.log(object.__proto__[protoName]);
  
              object.__proto__[protoName] = new Proxy(originalFunction, {
  
                  apply(target, thisArg, argArray) {
                      console.log("you intercept this func");
  
                      return Reflect.apply(...arguments);
                  }
              });
          }
  
          return object;
  </code></pre>
  
  <p>And in another main.js, I write code like this:</p>
  
  <pre><code>var a=new A();
  a = _Intercept(a);
  var b=new B();
  b = _Intercept(b);
  a.Func1();
  </code></pre>
  
  <p>But in chrome console, there output two lines "you intercept this func"
  How could this happen? I've only apply a.Func1() clearly, why print two lines??</p>
  
  <p>And when I try delete  "b = _Intercept(b)" in main.js or delete "  return Reflect.apply(...arguments);" in function _Intercept, it will only print one line.
  Is anyone know about this situation ? Is my wrong use?Or ES6 Proxy bug?
  Or Someone gimme some better dynamic proxy in javascript rather than Proxy in ES6??</p>
  
  <p>I've tried another version before, use objectPrototypes  rather than <strong>proto</strong>, but it works no good.</p>
  
  <pre><code> objectPrototypes[name] = new Proxy(originalFunction, handler); 
  </code></pre>