Honestly, it's even better to just not do this in the first place. If you're gonna screw with it, might as well wrap it in a function. That also gives you some extra control, like having a variable for debug level and silently eating logs below the level you care about.
Should be fine on modern javascript engines, but older ones can still have a problem with it. I just ran into a bug with this recently at work. I was porting some code over to a smart tv, and it threw an exception. The cause was an un-bound console.log (and console.warn and console.error) function.
14
u/Asmor Dec 16 '18
This won't work. Or at least, it didn't used to work. I haven't tried it in a very long time.
You'd need to do
print = console.log.bind(console).