title: Adding some pre and post logic to a bunch of JavaScript methods
body: <p>I have a JavaScript object</p>
  
  <pre><code>myObject = function () {
      var that = {};
      ...
      that.myMethod1 = myMethod1;
      that.myMethod2 = myMethod2;
      ...
      that.myMethodN = myMethodN;
      return that;
  }
  </code></pre>
  
  <p>I want to add the exact same pre and post logic to every method. For example a log for entering the method and for exiting the method.</p>
  
  <p>I could with a prePostLogic function such as </p>
  
  <pre><code>function prePostLogic(f2) {
      console.log('&gt;&gt; enter');
      f2();
      console.log('&lt;&lt; exist');
  }
  </code></pre>
  
  <p>and then do:</p>
  
  <pre><code>myObject = {
      ...
      that.myMethod1 = prePostLogic(myMethod1);
      that.myMethod2 = prePostLogic(myMethod2);
      ...
      that.myMethodN = prePostLogic(myMethodN);
      return that;
  }
  </code></pre>
  
  <p>But what I'd really like is to not have to wrap every method but to write something that would iterate over all methods and wrap them for me.  This is so when someone adds a new method they don't have to wrap it.</p>
  
  <p>Please help me?</p>
  
  <p>Thanks</p>