-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
Description
Today disableConsoleOutput looks like this:
const func = function () {};
const that = GLOBAL;
if (!that.console) {
that.console = (function (func){
const c = {};
c.log = func;
c.warn = func;
c.debug = func;
c.info = func;
c.error = func;
c.exception = func;
c.table = func;
c.trace = func;
return c;
})(func);
} else {
that.console.log = func;
that.console.warn = func;
that.console.debug = func;
that.console.info = func;
that.console.error = func;
that.console.exception = func;
that.console.table = func;
that.console.trace = func;
}
Yes, it just works, but if we type console.log
in console, we see empty function:
My improvement idea is to override toString
method to make it look more realistic:
For this you need add just 3 lines of code to current template:
var toString = () => "function () { [native code] }";
toString.toString = toString;
func.toString = toString;
Now it looks more realistic, but still not perfect. We can bind original toStinrg
method to new empty function:
Now console.log
looks like native function.
const cons = window.console;
for(let key in cons){
const originalFunction = cons[key];
if(typeof originalFunction !== "function") continue;
const func = function () {};
func.toString = originalFunction.toString.bind(originalFunction);
cons[key] = func;
};
I'm not sure this improvement matters, or just "works - don't touch"
UPD: seems it don't work for firefox, just Chromium, but Chromium is used by more users
sanex3339