【问题标题】:JavaScript Function Parameter Intellisense in Visual Studio 2015Visual Studio 2015 中的 JavaScript 函数参数 Intellisense
【发布时间】:2017-01-14 16:45:01
【问题描述】:

我阅读了这篇文章 (https://blogs.msdn.microsoft.com/visualstudio/2015/06/10/javascript-editor-improvements-in-visual-studio-2015/),看起来他们在 2015 年对 JS 智能感知做了一些很好的改进,但我想知道是否有办法为我作为参数传递给功能。

例如,如果我使用 JSDoc 的 typedef 语法定义了一个类型 (Cat),然后使用他们的语法说我的 PetTheCat 函数的参数是 Cat 类型,有什么方法可以让我对 cat 参数进行智能感知在 PetTheCat 的函数体内?

/**@typedef Cat
@property {string} Name*/
Cat = function()
{
    this.Name = null;
}

/**@method PetTheCat
@param {Cat} cat: The cat to pet.
*/
PetTheCat = function(cat)
{
    console.log(cat.Name + " is purring.");
}

如果我使用 new 运算符(即 var kitty = new Cat())声明一个对象,我可以获得完整的智能感知,如果我调用 PetTheCat({}),我现在可以为 cat 的成员获取智能感知,但是我似乎无法在实际函数中找到它,键入“cat”。只会产生未解析符号的标准列表。有没有办法在函数体内的“猫”上获得智能感知?

【问题讨论】:

    标签: javascript visual-studio parameter-passing intellisense


    【解决方案1】:

    当我在 VS 中了解 JS 智能感知时,我是通过 XML 文档了解的。要提供参数智能感知,您需要 <param> XML 标记。

    function Cat(name)
    {
        this.Name = name || "Cat";
    }
    
    var x = new Cat("kitty");
    
    function PetTheCat(cat)
    {
        /// <param name='cat' type='Cat' />
        console.log(cat.Name + " is purring!");
    }
    

    【讨论】:

      猜你喜欢
      • 2016-08-22
      • 2017-02-01
      • 2015-10-13
      • 2011-06-16
      • 1970-01-01
      • 2015-10-27
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      相关资源
      最近更新 更多