Javascript 类型错误:console.log.apply 上的非法调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8159233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: Illegal Invocation on console.log.apply
提问by Hymansonkr
If you run this in the chrome console:
如果您在 chrome 控制台中运行它:
console.log.apply(null, [array])
Chrome gives you back an error:
Chrome 会给你一个错误:
// TypeError: Illegal Invocation
Why? (Tested on Chrome 15 via OSX)
为什么?(通过 OSX 在 Chrome 15 上测试)
回答by Pavel Podlipensky
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.
这是意料之中的,因为 console.info 期望它的“this”引用是控制台,而不是窗口。
console.info("stuff") stuff undefined console.info.call(this, "stuff") TypeError: Illegal invocation console.info.call(console, "stuff") stuff undefined
这种行为是意料之中的。