title: Javascript: know which object function has been called
body: <p>I would like to know if there is a way to be notified when any object function is called, in javascript.</p>
  
  <p>For example, I would like to do something like the following:</p>
  
  <p>If I have an object like this:</p>
  
  <pre><code>myObject = {
      functionOne: function(argumentOne) {
          // do some stuff
      },
  
      functionTwo: function() {
          // do some stuff
      }
  }
  </code></pre>
  
  <p>And add a listener (or anything else to track the actions taken place on this object):</p>
  
  <pre><code>myObject.addEventListener('onFunctionCall', functionHasBeenCalled);
  </code></pre>
  
  <p>When I call:</p>
  
  <pre><code>myObject.functionOne('hello');
  </code></pre>
  
  <p>The listener handler to fire with information about the called function:</p>
  
  <pre><code>functionHasBeenCalled(calledFunctionData) {
      console.log(calledFunctionData.functionName + ' has been called');
      console.log('with argument: ' + calledFunctionData.functionArgument);
  }
  </code></pre>
  
  <p>And the console output to be:</p>
  
  <pre><code>functionOne has been called
  with argument: hello
  </code></pre>
  
  <p>Maybe there is another way, to implement this, not with an event listener, but I have no clue.</p>
  
  <p>Thanks!</p>