2021年3月13日星期六

Optional Chaining - Function.prototype.apply was called on undefined, which is an undefined and not a function

Using optional chaining with function calls causes the expression to automatically return undefined instead of throwing an exception if the method isn't found.

Note: The code is using spread syntax, not rest parameters.

const fn1 = undefined  const args = []  const fn2 = () => {}  const fn3 = () => {}    console.log(fn1?.(...args, fn2, fn3))  

Error:

console.log(fn1?.(...args, fn2, fn3))                                  ^  TypeError: Function.prototype.apply was called on undefined, which is an undefined and not a function  
https://stackoverflow.com/questions/66609657/optional-chaining-function-prototype-apply-was-called-on-undefined-which-is-a March 13, 2021 at 10:46AM

没有评论:

发表评论