title: Javascript - Override console.log and keep the old function
body: <p>I would like to override console.log and call it on my new function.</p>
  
  <p>I try something like this but I get <code>Uncaught TypeError: Illegal invocation</code>:</p>
  
  <pre><code>console.log = function() {
    this.apply(window, arguments);
  }.bind(console.log);
  
  console.log('as');
  </code></pre>
  
  <p>This is my goal:</p>
  
  <p><code>console.error(exception);</code> should do:</p>
  
  <pre><code>console.error = function() {
    if (typeof exception.stack !== 'undefined') {
      console.error(exception.stack);
    } else {
      console.error.apply(windows, arguments);
    }
  }.bind(console.error);
  
  console.error('as');
  console.error({stack: 'my stack....'});
  </code></pre>
  
  <p><strong>EDIT:
  Actually, it works in firefox and not in Chrome...</strong>
  It's a bug in Chrome: <a href="https://code.google.com/p/chromium/issues/detail?id=167911" rel="noreferrer">https://code.google.com/p/chromium/issues/detail?id=167911</a></p>