How to write comments for JavaScript code to support IntelliSense

Source: Internet
Author: User

IntelliSense is very handy when you are developing with Visual Studio. Starting with VS2008, IntelliSense support for JavaScript is provided. For example

In the above code, we first get an element with ID Form1 in the document using the getElementById of the Documents object, which is actually the default form element. We then assign it to a variable named F.

Then, when we use the variable F, we can automatically list some of the members that the form element should have, such as action and so on.

These belong to the IntelliSense of the default elements and methods, assuming that we have some custom JS code ourselves, how can it be IntelliSense?

The answer is: IntelliSense for custom methods is automatic.

For example, we add a method to the page as follows

function Helloworld (name) {
Alert ("Hello," + name);
}

And then in any part of the document, we want to call the method, which can be automatically recognized by IntelliSense

This kind of IntelliSense should be the most basic. However, we often write code in C # when there is another better IntelliSense: that is not only to list the method name, and there will be a detailed description of the method and its parameters, the return value, so that the user can better use the method. As shown below

How does this come about? Actually, this is done by annotations, as shown below

<summary>
Return a greeting according to a person's name
</summary>
<param name= "Name" > people to greet </param>
<returns> return Greeting </returns>
public string Helloworld (string name)
{
Return "Hello," + name;
}

This annotation, which we call XML annotations, is a new feature that starts with. NET 2.0.

Well, with the knowledge above, if we need to add a similar IntelliSense hint to our JavaScript code, can we also use annotations?

Yes, we can do this.

function SomeMethod (A, b) {
<summary>
This is a way
</summary>
<param name= "A" > This is the parameter a</param>
<param name= "B" > This is the parameter b</param>
The return value of the <returns> method </returns>
return "Hello,worod";
}

What's different is that these annotations are written inside the method, rather than written outside of the method, as in C #. Furthermore, if you want to implement such a function, the above functions cannot be written directly in the ASPX page, but instead write a single JS file. such as Default.js

Then add a reference to the JS in the ASPX

<script src= "Default.js" type= "Text/javascript" ></script>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.