可选链-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 错误,我已经在那里提交了,希望它会很快得到修复。
更新:已修复。
THE END
二维码