title: Best way to detect when a function is called from the console
body: <p>I would like to know the best way to detect when a method or function is directly called through the console. As far as I currently understand, it's not possible to directly detect it on identical function calls, but using the <code>.call()</code> and <code>.apply()</code> methods of a function I can pass additional data through the <code>this</code> object.</p>
  
  <p>Given the following code structure:</p>
  
  <pre><code>(function(){
      var Player = {money: 0};
      window.giveMoney = function(amount){
          if (this.legit !== true)
              throw new Error("Don't try to cheat!");
  
          Player.money += amount;
      }
  })();
  </code></pre>
  
  <p>I could call the function using</p>
  
  <pre><code>window.giveMoney.call({legit: true}, 300);
  </code></pre>
  
  <p>in my actual code to tell a direct call from the console and my own code apart, but this is obviously not fool-proof, since the same code can also be executed from the console to achieve the desired effect.</p>
  
  <p>I would want a way to be able to call the function from both places and then tell the locations of the call apart. If there's no way to do that, what's the best way to try and prevent the execution anyway? Is it best to just not expose any methods at all, and keep everything inside a single closed-off anonymous function?</p>