【发布时间】:2021-08-23 18:00:32
【问题描述】:
我正在尝试在 ie8 中使用“Function.prototype.call”而不是“Function.prototype.apply”。
function testLog(){
console.log.apply(console, arguments) // not supported 'apply' ie8
}
testLog(1,2,3) // 1,2,3
'Function.prototype.apply'在ie8中不支持,
function testLog(){
// console.log.call(console, ...arguments) //not supported 'spread operator' ie8
console.log.call(console, Array.prototype.slice.call(arguments));
}
testLog(1,2,3) // [1,2,3]
我尝试使用“Function.prototype.call”,但遇到了麻烦,因为 ie 不支持扩展运算符。
如何使用 'Function.prototype.call' 获得 1,2,3 而不是 [1,2,3]?
补充说明
我没有发现 ie8 不支持 console.log。
但是, console.log 是作为示例编写的。我希望重点应该放在“申请”和“打电话”上
另外,目前在 ie8 上运行,'call' 已启用,'apply' 仍然不可用。
[申请]https://caniuse.com/?search=ES%205.1%3A%20generic%20array-like%20object%20as%20arguments
[呼叫]https://caniuse.com/?search=JavaScript%20built-in%3A%20Function%3A%20call
【问题讨论】:
-
apply应该是 supported since IE 5.5。console.log.apply(console, Array.prototype.slice.call(arguments));应该可以正常工作。你确定你需要担心的不是console.log吗?你真的需要支持 IE 8 吗? -
我想知道它是否在 IE8 中的
console.log上不受特别支持。console在 IE8 和 IE9 中非常非常奇怪(在 IE10 中甚至有点奇怪)。编辑:果然没有(也不是call)。 -
@SebastianSimon - IE8 很奇怪。尽管它支持
apply和call,但它不在console.log上支持它们(或者可能是其他主机提供的功能)。您可能知道这一点,但对于潜伏者来说:主机提供的函数不必是真正的 JavaScript 函数,它们只需是可调用的。旧 IE 提供的可调用对象不具备完整的 Function 功能。
标签: javascript function internet-explorer-8 function.prototype