简体   繁体   中英

JavaScript Function Parameter Intellisense in Visual Studio 2015

I read this article ( https://blogs.msdn.microsoft.com/visualstudio/2015/06/10/javascript-editor-improvements-in-visual-studio-2015/ ) and it looks like they made some good improvements to JS intellisense in 2015, but I was wondering if there was a way to get full intellisense for an object I pass as a parameter into a function.

For instance, if I define a type (Cat) using JSDoc's typedef syntax and then use their syntax to say that the parameter to my PetTheCat function is a Cat type, is there some way for me to get intellisense on the cat parameter inside the function body of 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.");
}

I can get full intellisense if I declare an object with the new operator (ie var kitty = new Cat()), and I can now get intellisense for the members of cat if I call PetTheCat({}), but I can't seem to get it inside the actual function, typing "cat." just results in the standard list of unresolved symbols. Is there some way to get intellisense on "cat" inside the function body?

When I learned about JS intellisense in VS, I learned about it via the XML documentation. To provide parameter intellisense you need the <param> XML tag.

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!");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM