You can always cheat your way into making the JS engine believe that
what you are passing is indeed a function like we already to with the
'arguments' pseudo-array when we use Array.prototype.slice to convert
it into a real array.

try with this:
Function.prototype.apply.apply(console.log, [console, arguments]);

(of course, this goes inside your function after the other checks for
the existence of a .log/.info property, just giving you the important
stuff here.)


On May 2, 4:37 am, Ger Hobbelt <[email protected]> wrote:
> 2011/5/2 Arian Stolwijk <[email protected]>
>
>
>
>
>
>
>
>
>
> > Another pretty nice console wrapper is:https://github.com/amadeus/dbg
>
> > On Mon, May 2, 2011 at 1:53 AM, Barry van Oudtshoorn <
> > [email protected]> wrote:
>
> >>  I have a console wrapper that I've shared here before, if you're
> >> interested --http://jsfiddle.net/yx5a9/5/.
>
> >> For the record, my check is: |if (window.console && console[type] &&
> >> console[type].apply) { ... }|. I've shared it here before, but its big
> >> advantage is that it has a toString method; elsewhere, I've bound an
> >> application alert to [Ctrl]+[Shift]+[`] that shows the results of toString.
> >> It makes debugging in IE infinitely simpler. :)
>
> I like 'em!  But... it's circumventing the question in a very nice way. (If
> I'd been of the female persuasion, I might have said something along the
> lines of 'you boys are sweet.') Guess I wasn't asking the question
> correctly.
> First half of my OP is crystal, given the whos' been answering: nope,
> mootools core doesn't have something like that. We have a way, though!
> Now let's rephrase the second half of the OP:
>
> Is it 'a commonly known fact' that console.log and friends aren't real
> _functions_ in IE9/IE8 (I checked: 9.08080 / 8.0.7600) and 'thus' do _not_
> offer the .apply() method, while all the other major browsers out there /do/
> present them as functions, so you can console.log.apply() there to your
> heart's content?
>
> Apparently, given these wrappers, the answer is a definite 'yes', but where
> the heck is this observation documented?
> That's the 64K question, because I can't find it! Am I blind?
> (Sure, there's nothing in the JS spec docs about console, so nothing is
> /wrong/, per se, it's just I can't find them in a quirks comparison chart or
> doc sheet anywhere, and this is spooky.)
>
> I like the 'console[type]' way of writing the check in Barry's case, but
> both 'wrappers' basically take a detour around IE console.log -- once you
> realize what you're looking at/for -- and offer one another way to view
> these info streams, more or less completely ignoring the existence of IE's
> console.log as:
>
>   if (console && console['log'] && console['log'].apply)
>   {
>     console.log('yep!');
>   }
>   else
>   {
>     console.log('FAIL'); // sic!
>   }
>
> in a IE8/9 console gives you:
>
>   LOG: FAIL
>
> Nothing wrong with those wrappers, they're absolutely fine and each in their
> own way way better than my bangings on keyboards, but my encounter with IE
> here feels way too much like sitting behind a workstation again, invisible
> BOFH in attendance, a Real Man's UNIX at your fingertips and then those
> _lovely_ manpages. ('apropos'?! Never heard of it. That's for wussies.
> 'gnu'?! We're running a business here, not a wildlife preservation area!)
> Maybe it's me not being a native English speaker, but those manpages always
> were absolutely, perfectly and concisely _exact_ and _correct_ in their
> description of the tools involved. _After_ the fact. Because at the time of
> despair those were of absolutely no help whatsoever when you didn't already
> know what to do anyhow.  This console.log thingy and my google fu gone
> utterly AWOL feels the same: you either know it, or you don't. Members only.
> Ain't got the tie? Too bad, son, maybe in another life.
>
> (I do recall a time when two aboriginal shamans were sitting there in the
> room with me, coffee at the ready in their paws, waiting for me to nuke
> myself, their AIX, most probably both, to Kingdom Come in a jiffy. We were
> very friendly and the atmosphere was that of a room full of friends watching
> some important racing event in expectation of some seriously spectacular
> crashes, with extra replay done John Woo style, but this here was the
> consultant acid test whether I was Man or Boy and they had already
> transgressed by telling me the VT there had the wrong TERM (termcap) config,
> so how did I want to edit this here file with vi? Luckily I remembered from
> the dregs of my festering brainbox that you don't get cursor keys then but
> you still have cursor keys... if you know where to find them in the
> alphanumerics. ;-)  I passed the test and all were merry after that, and
> this IE+google fail thing feels similar, only on a google/Net level now. So
> I'm rather interested in having a look at those manual pages now, assuming I
> passed. Or is IE the Redmond technological equivalent of selfdiscovery?)
>
> BTW: Another fun observation I ran into several months ago on my way to
> attain 'able' rating, according to my own opinion at least, when it comes to
> JS coding:
>
> - start IE8.
> - F12
> - type this in the console window (do NOT press that 'start debugging'
> button yet!):
>     if (console) { console.log('oy!'); }
>  and you get:
>    (X) error: console is "undefined"
>
> - hit the 'start debugging' button and try the same:
>   'oy!'
>
> The correct answer there was, of course, to check like this:
>   if (typeof console !== 'undefined')
> but the funny bit was that IE8 doesn't have an active 'console' until you've
> 'start debugging', or told it to go and debug the failure in your script in
> some web page. After that, the console doesn't go away.
>
> Ran into it because I had copy-pasted some guru code which had the 'if
> (console)' in there. My conclusion: the guru was a baboon like me, only with
> page ranking off the charts.
>
> That was another one of those; blamed it on my n00bness at the time; this
> time around, I don't want to rate myself n00b, while probably I am.
>
> --
> Met vriendelijke groeten / Best regards,
>
> Ger Hobbelt
>
> --------------------------------------------------
> web:    http://www.hobbelt.com/
>        http://www.hebbut.net/
> mail:   [email protected]
> mobile: +31-6-11 120 978
> --------------------------------------------------

Reply via email to