title: How do get the name of a calling function in Javascript?
body: <p>Consider the following example.</p>
  
  <pre><code>var obj = function(){};
  
  function apply(target, obj) {
  
      if (target &amp;&amp; obj &amp;&amp; typeof obj == "object") {
          for (var prop in obj) {
              target[prop] = obj[prop];
          }
      }
  
      return target;
  }
  
  apply(obj.prototype, {
      firstFunction: function (){
          this.secondFunction();
      },
      secondFunction: function (){
          // how do I know what function called me here?
          console.log("Callee Name: '" + arguments.callee.name + "'");
          console.log("Caller Name: '" + arguments.callee.caller.name + "'");
      }
  });
  
  var instance = new obj();
  
  instance.firstFunction();
  </code></pre>
  
  <p>UPDATE</p>
  
  <p>Both answers are really awesome. Thank you. I then looked into the problem of calling a recursive, or parent function within an object and found a solution here. This would allow me to retrieve the function name without using the arguments.callee/caller properties.</p>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/function" rel="nofollow">https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/function</a></p>