title: Why can't I use left hand assignment to modify value of function result?
body: <p>I'm trying to assign a value to the what the function return to me. I know this may sounds dumb at first glance but what I'm accomplishing is getting direct reference to alert (In C++, this is called as lvalues) and modify it.</p>
  <pre><code>function foo() {
    return alert;
  }
  
  foo() = &quot;zoo&quot;
  </code></pre>
  <p>Well,</p>
  <pre><code>var name = &quot;alert&quot;;
  var ref = (reference) =&gt; reference.split('.').reduce((o,i)=&gt;o[i], window)
  
  ref(name) = new Proxy(ref(name), {
      apply: (target, thisArg, args) =&gt; {
  
          console.log(thisArg)
          console.log(args)
      
          return &quot;Alert called&quot;;
      }
  });
  </code></pre>
  <p>I could do for now,</p>
  <pre><code>var name = &quot;alert&quot;;    
  window[name] = new Proxy(window[name], window), {
      apply: (target, thisArg, args) =&gt; {
  
          console.log(thisArg)
          console.log(args)
      
          return &quot;Alert called&quot;;
      }
  });
  </code></pre>
  <p>But it get complicated with complex objects like <code>&quot;HTMLCollection.prototype&quot;</code></p>
  <p>Even with eval, it doesn't work</p>
  <pre><code>var name = &quot;alert&quot;;
  
  eval(name) = new Proxy(eval(name), {
      apply: (target, thisArg, args) =&gt; {
  
          console.log(thisArg)
          console.log(args)
      
          return &quot;Alert called&quot;;
      }
  });
  </code></pre>