1

我看到似乎与 JavaScript参考指令不一致的行为。不过,我假设这是我的用户错误,并且想知道我不知道的内容。

我的项目中的文件夹(碰巧是一个 ASP.NET MVC 项目,但我不认为这有什么不同)按此层次结构组织:

Scripts
...MyOrg
......Models
.........Model1.js
......Support
.........Constants.js
.........Utility1.js
..._references.js

_references.js 在其他引用中包含此行,因此我不必在每个使用它的文件中包含对 Constants.js 的引用(Mads Kristensen对 _references.js的引用):

/// <reference path="MyOrg/Support/Constants.js" />

我也尝试过这种不应该(也没有)产生影响的替代形式:

/// <reference path="~/Scripts/MyOrg/Support/Constants.js" />

Model1.js 和 Utility1.js 都使用 Constants.js 中的一个项目,例如

var msg = MyOrg.Constant.Message103;

根据 _references.js 中的引用,Model1.js 正确地识别出引用来自 Constants.js。但是 Utility1.js 使用警告标记使用(“使用隐式声明的全局变量 'MyOrg'”),除非我在 Utility1.js 中添加另一个显式引用指令——这些工作中的任何一个:

/// <reference path="~/Scripts/NextIT/Support/Constants.js"/>
/// <reference path="Constants.js"/>

为什么 Utility1.js 无法识别来自 _references.js 的引用?

4

0 回答 0