TypeError:Date不是构造函数 [英] TypeError: Date is not a constructor



所以,我一直在为我公司制作表格一段时间以来,过去非常简单的Javascript对我有用。然而,突然之间,它正在推出错误: TypeError:Date不是构造函数

So, I've been making forms for my company for some time now with pretty easy Javascript that has worked for me in the past. However all of a sudden it's kicking out the error: TypeError: Date is not a constructor


var Date = this.getField("Text1");
Date.value = util.printd("mm/dd/yyyy",new Date());

它适用于我所有旧表格,但现在它不适用于新表格...我已经尝试在旧表单上创建一个新按钮 - 只需复制并粘贴代码,然后它将打破所有其他按钮并吐出相同的错误。

It works on all my old forms, but now it won't work on new ones... and I've tried making a new button on an old form - just copying and pasting the code, and then it'll break all the other buttons and spit out the same error.

运行:Windows 7 64位,Acrobat XI 11.0.10

Running: Windows 7 64-bit with Acrobat XI 11.0.10


变量 Date 隐藏全局函数 日期 并导致此错误。由于JS中的作用域如何工作,因此最重要的是使用名称。

The variable Date is hiding the global function Date and causing this error. Because of how scoping works in JS, the inner-most use of a name is the one that matters.

在这种情况下,您声明 var日期,它成为该函数所知道的唯一日期。当您为其指定字段或文本( Date = this.getField ... )时,您将隐藏全局类。

In this case, you declare var Date which becomes the only Date the function knows about. When you assign it a field or text (Date = this.getField...), you hide the global class.

您可以重命名您的变量(我建议 date ,因为大写名称通常是为类型保留的)或显式引用 new window.Date 当你去构建一个新的日期时。

You can rename your variable (I would suggest date, as capital names are typically reserved for types) or explicitly reference new window.Date when you go to construct a new date.


登录 关闭
发送“验证码”获取 | 15天全站免登陆