title: Is there a way to override a global variable in a closure's scope?
body: <p>I have an API has a signature like</p>
  <pre><code>on(eventName, Handler)
  </code></pre>
  <p>Where API users use it like</p>
  <pre><code>on('myEvent', (safeAccessObject) =&gt; {
    safeAccessObject.doSomething();
  });
  </code></pre>
  <p>Sometimes though, users refer to a global that I'd prefer them not to:</p>
  <pre><code>// assume window.dangerousAccessObject is defined
  
  on('myEvent', (safeAccessObject) =&gt; {
    dangerousAccessObject.doSomethingUnintended();
  });
  </code></pre>
  <p><strong>Is there a way to set <code>dangerousAccessObject</code> to <code>null</code> or even use some proxy of my own only within the closure of their handler?</strong></p>
  <p>The idea is not to create a complete and secure sandbox, but rather show helpful debug messages to the API users. In this instance both the API of <code>on</code> as well as <code>dangerousAccessObject</code> are production code that user code relies on in other contexts and so it can't be removed.</p>