title: Get caller instance from inside function
body: <p>I currently have a few large files that I'd like to break up into smaller ones to ease editing. I feel as though these 'code snippets' wouldn't merit being created as a module and/or would have conflicts with scope if made as such.</p>
  
  <p>So instead I'd perfer to just import the contents from these 'clipped' files, into the current execution scope and then eval them. Figured I'd write a helper function to do this(set in the global scope via the 'main' js file.) but I've ran into a snag. </p>
  
  <p>Is there a way to get the calling instance from within the called function.</p>
  
  <p>What I have so far:</p>
  
  <pre><code>global.acquire = (function() {
      var cache = {};
      var fileReader = require('fs');
      return function (file, updateCache) {
          var f = require.resolve(file);
          if (f) {
              if (cache.hasOwnProperty(f) &amp;&amp; !updateCache) {
                  res = cache[f];
              } else {
                  res = fileReader.readFileSync(f, {encoding: "utf8"});
              }
              cache[f] = res;
  
              // Is there a way to get the calling function's instance so the eval will execute from the caller's scope? 
              return eval.apply(caller, '(' + res + ')');
          } else {
              throw "File not found";
          }
      }
  }());
  </code></pre>
  
  <p>I know I could either pass the instance, or acquire.apply(), but that feels a bit sloppy if I can retrieve the instance from within the function.</p>