Last active
August 21, 2017 10:00
-
-
Save cfj/9857886 to your computer and use it in GitHub Desktop.
More console.log sillyness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
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);
};
And don't forget:
console.log.toString = function(){return _log.toString();};
@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
See
evil.js
.Also note that
string.split('').reverse().join('')
is not a very good way to reverse a string in JavaScript.