javascript - js override console.log if not defined -


which solution recommend, second simpler ( less code ), there drawbacks on using ?

first: (set global debug flag)

// first line of code var debug = true; try {     console.log } catch(e) {     if(e) {         debug=false;     } }; // later in code if(debug) {     console.log(something); } 

second: override console.log

try {     console.log } catch(e) {     if (e) {         console.log = function() {}     } }; // , need in code console.log(something); 

neither, variation of second. lose try...catch , check existence of console object properly:

if (typeof console == "undefined") {     window.console = {         log: function () {}     }; }  console.log("whatever"); 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -