javascript - 可选链接 - Function.prototype.apply 在未定义时调用,这是未定义而不是函数

标签 javascript node.js google-chrome v8 optional-chaining

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


注意:代码使用 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的bug,我已经提交了there ,希望它会尽快修复。
更新:it has been fixed .

关于javascript - 可选链接 - Function.prototype.apply 在未定义时调用,这是未定义而不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66609657/

相关文章:

javascript - 尝试将 json 值与局部变量相乘时出现 NaN

javascript - 不使用函数的 Vanilla Javascript 倒计时器

node.js - axios get 请求挂起,没有错误,catch 未触发

node.js - 使用 Socket.io 为不同的房间设置不同的定时器

node.js - 构建期间 NODE_ENV 的解决方法

javascript - 以编程方式访问浏览器中的网页错误详细信息

browser - Chrome 浏览器中,除非网址前面有 www,否则网站不可用,有什么技巧可以解决此问题吗?

javascript - 如何在 JavaScript 中访问父类(super class)的私有(private)成员?

javascript - 如何为 View 提供子字符串对象? Express.js

javascript - NodeJS 中的 CORS 支持在 Chrome 中不起作用