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

Wen*_* Du 16 javascript google-chrome v8 node.js optional-chaining

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

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

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

console.log(fn1?.(...args, fn2, fn3))
Run Code Online (Sandbox Code Playgroud)

错误:

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

Wen*_* Du 8

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

更新:已修复