Sort of...
you can always store any JavaScript method inside a variable, replace it's implementation, do your own stuff and finally restore it.
From your question it is unclear if this might be a solution for your Problem, I just mention this because of all the "Not possible" comments.
https://jsfiddle.net/3grfL30s/
function alertSomething(cp){
alert("TEST: " + cp);
}
alertSomething(1);
// from here i dont want alerts, no matter what code is calling the method
// backup method to "x" to restore it later.
var x = alertSomething;
alertSomething = function(){} //overwrite alertSomething to do nothing
//do my work, verify alertSomething is doing nothing
alertSomething(2);
//restore alert method
alertSomething = x;
//verify its working agian
alertSomething(3);
This would produce the alerts 1 and 3, even if 2 would have been called while your code is beeing executed.
For more complex methods or non-boolean execution conditions, the Proxy Pattern with additional "flags" can be useful (Example still boolean, but there could be multiple conditions):
https://jsfiddle.net/3grfL30s/1/
function alertSomething(cp){
alert("TEST: " + cp);
}
var doIt = 1;
var originalAlert = alertSomething;
alertSomething = function(cp){
if (doIt){
return originalAlert.apply(this, arguments);
}
}
alertSomething(1);
// in here i dont want alerts
doIt = 0;
//do my work, verify alertSomething is doing nothing
alertSomething(2);
//restore alert method
doIt = 1;
//verify its working agian
alertSomething(3);