我有多个 javascript 文件,它们有自己的功能。如果我在其中任何一个内部引用其中一个,如果该函数不是原型(prototype),它就看不到它的函数。 Intellisense 内部的逻辑是什么?
我想将 Splash 功能与下面的 Intellisense 功能一起使用,我该怎么做?
//My.js
/// <reference path="Test.js" />
.
//Test.js
NameSpace.prototype.UI = new function () {
this.Splash = function (value) {
try {
if (value == 1) {
$('#splash').css('height', $(document).height());
$('#splashContent').css('top', $(window).height() / 2);
$('#splash').fadeIn();
$('#splashContent').fadeIn();
setTimeout("SF.UI.Splash(0)", 3000);
}
else if (value == 0) {
$('#splash').fadeOut(1000);
$('#splashContent').fadeOut(1000);
}
else if (value == 3) {
$('#splash').css('height', $(document).height());
$('#splashContent').css('top', $(window).height() / 2);
$('#splash').fadeIn();
$('#splashContent').fadeIn();
}
} catch (e) {
Splash(0);
}
}
}
最佳答案
JS Intellisense 充其量是不稳定的。尽管有所有这些文章,但根据我的经验,它并不像广告中那样起作用。我建议:
- 确保所有 JS 文件都在同一个项目中(让 ti 跨项目工作甚至更棘手)。
- 确保
/// <reference path="Test.js" />
是 JS 中的第一行。 - 确保
Test.js
中没有错误文件(请在其上运行 JSLint 以确保)或使用 vsdoc 方法。 - 查看
Output
工具窗口以查看它是否包含与更新智能感知相关的任何错误。这将帮助您排除故障并删除引用的 JS 文件中的错误。
创建 Test-vsdoc.js
的替代方案文件(这样,即使你的主 JS 文件有错误,也不会导致智能感知失败):
//Test-vsdoc.js
NameSpace.prototype.UI = new function () {
this.Splash = function (value) {
/// <summary>This is my function summary</summary>
}
}
VS 会在您下次重新启动 IDE 时自动包含它(或尝试强制更新 Ctrl+Shift+J)
关于javascript - 我应该怎么做才能在 Visual Studio 中为我自己的 js 库获取 javascript 智能感知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6452760/