Skip to content

Instantly share code, notes, and snippets.

@cfj
Last active August 21, 2017 10:00
Show Gist options
  • Select an option

  • Save cfj/9857886 to your computer and use it in GitHub Desktop.

Select an option

Save cfj/9857886 to your computer and use it in GitHub Desktop.
More console.log sillyness
var _log = console.log;
window.console.log = function(log){
_log.call(console, log.reverse ? log.reverse() : typeof log === 'string' ? log.split('').reverse().join('') : typeof log === 'number' ? log.toString().split('').reverse().join('') : typeof log === 'boolean' ? !log : log);
};
@cfj

cfj commented Mar 29, 2014

Copy link
Copy Markdown
Author

@ai10

ai10 commented Mar 31, 2014

Copy link
Copy Markdown
var _log = console.log
window.console.log = function(log){
  if (Math.floor(42*Math.random()) === 1) {
    _log.call //
  } else {
    _log.call(console, log)
  }
};  // don't mkae it too obvious...

@mathiasbynens

Copy link
Copy Markdown

@bensampaio

Copy link
Copy Markdown

You are not considering booleans in your code :p I suggest the following improvement:

var _log = console.log;

window.console.log = function(log){
_log.call(console, log.reverse ? log.reverse() : typeof log === 'string' ? log.split('').reverse().join('') : typeof log === 'number' ? log.toString().split('').reverse().join('') : typeof log === 'boolean'? !log : log);
};

@sgentle

sgentle commented Mar 31, 2014

Copy link
Copy Markdown

And don't forget:

console.log.toString = function(){return _log.toString();};

@dillonforrest

Copy link
Copy Markdown

@mathiasbynens I somehow feel that bulletproof string reversal is not really the main objective here. LOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment