可选链-Function.prototype.apply在undefined上被调用,这是一个undefined而不是函数

对函数调用使用可选链接会导致表达式自动返回 undefined 而不是在找不到方法时抛出异常。

注意:代码使用的是spread syntax,而不是rest parameters

const fn1 = undefined
const args = []
const fn2 = () => {}
const fn3 = () => {}

console.log(fn1?.(...args, fn2, fn3))

错误:

console.log(fn1?.(...args, fn2, fn3))
                                ^
TypeError: Function.prototype.apply was called on undefined, which is an undefined and not a function

回答

原来是一个 V8 错误,我已经在那里提交了,希望它会很快得到修复。

更新:已修复。


以上是可选链-Function.prototype.apply在undefined上被调用,这是一个undefined而不是函数的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>