In Javascript, is there any way to prevent a function from being called in a certain section of code? I want to make sure that the function “alert” is not called in a specific section of code.
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
In this case, how should I implement the functions allowFunctionToBeCalled and preventFunctionFromBeingCalled?
You can sort of achieve this like so:
But it is major hax.