Very handy console.log
method does exist in IE9, but for some obscure reason it's not a function. No, really
>> typeof console.log
"object"
So it cannot be .call
'ed or .apply
'ed or be set as callback to String.prototype.replace
. That's unfair.
This function wraps native console.log
method into a function so it becomes a function again. It does nothing with normal browsers and older ones. It takes no arguments and returns nothing.
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.
To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.
140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.
@atk, thanks for your suggestion!
I suppose we can forget about old FF2 (3?) with its "empty catch statement" parser bug.
One tricky thing I've noticed is
?:
operator allows AssignmentExpression within anda?0:b=42
is 1 byte shorter thana||(b=42)
So i came up with this code:
function(){try{var a=console,b=a.log,c=b.call?0:a.log=function(){c.apply.call(b,a,arguments)}}catch(e){}}
It should work, but I cannot test it in IE9 at the moment