Best way to detect when a function is called from the console
问题 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 .call() and .apply() methods of a function I can pass additional data through the this object. Given the following code structure: (function(){ var Player = {money: 0}; window.giveMoney = function(amount){ if (this.legit !== true) throw new Error("Don't try to cheat!");