TypeError: Illegal Invocation on console.log.apply
26,993
It may not work in cases when execution context changed from console to any other object:
This is expected because console.info expects its "this" reference to be console, not window.
console.info("stuff") stuff undefined console.info.call(this, "stuff") TypeError: Illegal invocation console.info.call(console, "stuff") stuff undefined
This behavior is expected.
https://bugs.chromium.org/p/chromium/issues/detail?id=48662
Author by
Jacksonkr
Another guy in a chair with questions & answers. jacksonkr.com
Updated on July 27, 2022Comments
-
Jacksonkr almost 2 years
If you run this in the chrome console:
console.log.apply(null, [array])
Chrome gives you back an error:
// TypeError: Illegal Invocation
Why? (Tested on Chrome 15 via OSX)
-
C B over 10 yearsIf you need to use as a function, you can use console.info.bind(console)
-
mucaho almost 9 yearsso can you use
console.info.call(console, "stuff")
in all browsers that support ES5? -
PeterM about 8 yearsSame goes for apply:
console.info.apply(console, arguments)
-
Alan C. S. almost 8 yearsSame argument applies to other functions such as console.log() and document.writeln(). So, always provide the correct execution context if using call() or apply(). Alternately, use bind() as @JohnWilliams has pointed out.
-
Benny Bottema about 7 yearsThis is still applicable to IE11/Edge when the DevTools F12 are not open.