Skip to content

Instantly share code, notes, and snippets.

@cfj
Last active August 21, 2017 10:00
Show Gist options
  • Save cfj/9857886 to your computer and use it in GitHub Desktop.
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
Copy link
Author

cfj commented Mar 29, 2014

@ai10
Copy link

ai10 commented Mar 31, 2014

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...

@bensampaio
Copy link

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
Copy link

sgentle commented Mar 31, 2014

And don't forget:

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

@dillonforrest
Copy link

@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