【问题标题】:Uncaught TypeError: Failed to construct 'File': Please use the 'new' operator, this DOM object constructor cannot be called as a function未捕获的类型错误:无法构造“文件”:请使用“新”运算符,此 DOM 对象构造函数不能作为函数调用
【发布时间】:2015-09-24 01:36:24
【问题描述】:

我试图用

创建文件对象
var file = File("path/to/some/file");

按照链接https://developer.mozilla.org/en-US/docs/Extensions/Using_the_DOM_File_API_in_chrome_code中的建议。

但是,出现以下错误

Uncaught TypeError: Failed to constructor 'File': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

如何修复它并将文件路径链接到 javascript 中的文件对象?

【问题讨论】:

  • 好吧,您是否尝试使用 new File("..") 代替?成功了吗?
  • 您正在为 Firefox 扩展编写 chrome 代码吗?从该页面的前三句话:“如果你想在 chrome 代码中使用 DOM File API,你可以不受限制地这样做。事实上,你有一个额外的功能:你可以创建指定文件路径的 File 对象在用户的计算机上。这仅适用于特权代码,因此网络内容无法做到这一点。"

标签: javascript jquery


【解决方案1】:

这表明你应该像这样调用构造函数:

var file = new File("path/to/some/file");

【讨论】:

    猜你喜欢
    • 2017-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-17
    • 1970-01-01
    • 2017-04-09
    • 2017-08-02
    相关资源
    最近更新 更多