可选链接 - Function.prototype.apply 被调用未定义,这是未定义的而不是函数
Optional Chaining - Function.prototype.apply was called on undefined, which is an undefined and not a function
注意:代码使用spread syntax
, not 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
有一些规则要遵循...剩余参数。
其中一条规则是 ...rest 参数只能是最后一个参数。
foo(...one, ...wrong, ...wrong)
foo(...wrong, bad, bad)
foo(ok, ok, ...correct)
参见:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters
原来是V8的bug,提交了there,希望尽快修复
注意:代码使用spread syntax
, not 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
有一些规则要遵循...剩余参数。
其中一条规则是 ...rest 参数只能是最后一个参数。
foo(...one, ...wrong, ...wrong)
foo(...wrong, bad, bad)
foo(ok, ok, ...correct)
参见:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters
原来是V8的bug,提交了there,希望尽快修复