JavaScript引用指令未按预期工作

时间:2014-07-24 19:00:17

标签: javascript javascript-intellisense

我看到JavaScript reference directives的行为似乎不一致。我假设这是我的用户错误,但我想知道我不知道的事情。

我的项目中的文件夹(恰好是一个ASP.NET MVC项目,但我不认为这会产生影响)在这个层次结构中组织起来:

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

_references.js包含此行中的其他引用,因此我不必在每个使用它的文件中包含对Constants.js的引用(Mads Kristensen为reference about _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;

Model1.js正确地认识到引用来自于_references.js中引用的Constants.js。但是Utility1.js标记了使用时带有警告(&#34;使用隐式声明的全局变量&#39; MyOrg&#39;&#34; )除非我添加另一个显式引用指令在Utility1.js中 - 这些工作之一:

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

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

0 个答案:

没有答案