Sunday, May 19, 2024
187
rated 0 times [  190] [ 3]  / answers: 1 / hits: 24133  / 13 Years ago, thu, march 1, 2012, 12:00:00

When I execute the following code in Chrome 18 beta I get the error:



console.log.apply(this, ['message']);



TypeError: Illegal invocation.




In Firefox 10 it works as expected.



In IE9 I get the error: Object doesn't support property or method 'apply'.



I'm guessing this has to do with how the browser has implemented console.log.



Why does it work in Firefox but not in Chrome and IE? I'm hoping someone can shed some light on the cause of this and its ramifications.



Here is an executable sample on JS Bin.


More From » internet-explorer

 Answers
30

console and log are host objects. Their behavior is implementation dependent, and to a large degree are not required to implement the semantics of ECMAScript.



FWIW, your jsBin fails in Chrome as well unless you change it to...



console.log.apply(console, ['message']);


but that seems to be that log simply anticipates a calling context of console.


[#87102] Thursday, March 1, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
roberts

Total Points: 212
Total Questions: 101
Total Answers: 101

Location: Philippines
Member since Thu, Apr 14, 2022
2 Years ago
;