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>