javascript - 我应该怎么做才能在 Visual Studio 中为我自己的 js 库获取 javascript 智能感知

标签 javascript visual-studio visual-studio-2010 intellisense

我有多个 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/

相关文章:

javascript - JSDoc 和 JavaScript 单例文档

javascript - 当我尝试插入两条记录时,CUR_STOCK 表中只有一条记录得到更新?

visual-studio - 如何让 Visual Studio 始终重新加载更改的解决方案、项目和文件?

visual-studio - Visual Studio Code 和 Visual Studio 之间有什么区别?

c# - .NET 将类解析为错误的 DLL

javascript - 微信(WebGL)小游戏无法在设备上运行,但可以在 devtool 中运行

javascript - 使用 REST API 时,Meteor 是否保留 react 性

c# - 用于 ASP.NET MVC 的 Visual Studio 模板导出

visual-studio - Visual Studio 2010, "File > Recent Projects and Solutions"不是事件的!

c# - Visual Studio - 在不启动浏览器的情况下调试 Web 应用程序(运行本地 IIS)