title: Is it thread safe using variables between closures in javascript?
body: <p>I was reading an <a href="http://www.nmjenkins.com/2010/04/privateprotected-without-using-caller.html" rel="nofollow">article</a> about private/protected members "emulation"
  with javascript ( i know it's not a <em>best practice</em> but it's for <em>research purpose</em> )</p>
  
  <p>For example, in this code we've:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var Class = (function() { // Open closure
  
  var caller = null;
  
  //[...]
  
  var mayAccessWrapped = false;
  function wrapmethod(method) {
  
      mayAccessWrapped = true;
      if (method.__getWrappedMethod) {
          method = method.__getWrappedMethod();
      }
      mayAccessWrapped = false;
  
      var wrapped = function wrapper() {
          var prevCaller = caller;
          caller = wrapper;
          var returns;
          try {
              returns = method.apply(this, arguments);
          }
          finally {
              caller = prevCaller;
          }
          return returns;
      };
      wrapped.__getWrappedMethod = function() {
          if (mayAccessWrapped) { return method; }
          throw "Error: only the wrapping function may access the wrapped method";
      }
      return wrapped;
  }
   
  //[...]
  
  return Class;
  
  })(); // End Class closure</code></pre>
  </div>
  </div>
  </p>
  
  <p>"wrapped" method is used multiple times from same object and it uses caller variable to "inject" informations about the "caller" with "called" method ( <a href="http://www.nmjenkins.com/2010/04/private-and-protected-fields-in.html" rel="nofollow">alternative to deprecated arguments.callee</a>).</p>
  
  <p>But, in a concurrent scope, is this way thread safe? Is it possible that another method can change the value of <strong>caller</strong> variable invalidating data consistency?</p>