在 Javascript 中,有什么方法可以防止某个函数在某段代码中被调用?我想确保在代码的特定部分中没有调用函数“alert”。
alert("Hi!"); //this should work normally
var al = alert
//the function "alert" cannot be called after this point
preventFunctionFromBeingCalled(alert, "Do not use alert here: use the abbreviation 'al' instead.");
alert("Hi!"); //this should throw an error, because "console.log" should be used instead here
allowFunctionToBeCalled(alert);
//the function "alert" can be called after this point
alert("Hi!"); //this should work normally
在这种情况下,我应该如何实现功能allowFunctionToBeCalled
和preventFunctionFromBeingCalled
?