title: Any way to get the currently executing function object in javascript?
body: <p>Is there any way to refer to the function object that you're currently executing in?  If it's not a method of any object or not called with <code>.call()</code> or <code>.apply()</code>, the <code>this</code> pointer is likely just <code>window</code>, not the function object.</p>
  
  <p>I often use a design pattern like this for global variables that I want scoped to a particular function as this keeps them out of the top level namespace:</p>
  
  <pre><code>function generateRandom() {
      if (!generateRandom.prevNums) {    
          generateRandom.prevNums = {};    // generateRandom.prevNums is a global variable
      }
      var random;
      do {
          random = Math.floor((Math.random() * (99999999 - 10000000 + 1)) + 10000000);
      } while (generateRandom.prevNums[random])
      generateRandom.prevNums[random] = true;
      return(random.toString());
  }
  </code></pre>
  
  <p>But, I'd rather not have to spell out the function name every time I want to use a variable scoped to that object.  If the name of the function ever changes, there are then a lot of places to change the name.</p>
  
  <p>Is there any way to get the currently executing function object?</p>