我已经能够为这样定义的“类”原型正确地运行javascript intellisense:
function GetCustomerList()
{
}
GetCustomerList.prototype =
{
HEADER: {
RETURN_CODE: 0,
RETURN_MESSAGE: "",
}
,
NUM_RECORDS: 0,
START_RECORD: 0,
END_RECORD: 0
};
我可以输入以下内容:
var req = new GetCustomerList();
req.HEADER.RETURN_CODE = 100;
而且Visual Studio的智能感知了解HEADER属性以及它自己的名为“ RETURN_CODE”和“ RETURN_MESSAGE”的属性.我可以:
req.NUM_RECORDS = 50;
随着智能感知的完美.
因此,Intellisense可以处理复杂的嵌套类型-很棒.但是,是否有可能通过一系列复杂类型获得智能感知?
例:
function Customer()
Customer.prototype = {
NAME: "",
ADDRESS: "",
ID: 0
};
function GetCustomerList()
{
}
GetCustomerList.prototype =
{
HEADER: {
RETURN_CODE: 0,
RETURN_MESSAGE: "",
}
,
NUM_RECORDS: 0,
START_RECORD: 0,
END_RECORD: 0,
CUSTOMERS: [ new CUSTOMER() ]
};
我有一个类型为“ CUSTOMER”的数组,我也为此定义了一个原型.我希望能够输入以下内容:
req.CUSTOMER[ 0 ].NAME
并且有intellisense提示我“ NAME”是可用于此数组的属性.
这可能吗?
解决方法:
更新:
正如您已经注意到的,IntelliSense可以很好地适用于您的复杂类型,但不适用于Array.即使您创建诸如String之类的内部类型数组,它也仍然无法正常工作.
我已经对这个主题进行了彻底的研究,从理论上讲,这应该可行,但事实并非如此.
作为测试,创建一个名为“ customers.js”的javascript文件,并包含以下内容:
function Customer() {
/// <summary>This is my custom intellisense for the Customer type</summary>
///<field name="NAME" type="String">The Customer's name</field>
///<field name="ADDRESS" type="String">The customer's address</field>
///<field name="ID" type="String">The ID number</field>
}
Customer.prototype = {
NAME: "",
ADDRESS: "",
ID: 0
};
function CustomerList() {
/// <summary>The List of Customers</summary>
///<field name="HEADER" type="String">The header</field>
///<field name="CUSTOMERS" type="Array" elementType="Customer" >The list of customers in an Array</field>
}
CustomerList.prototype =
{
HEADER: {
RETURN_CODE: 0,
RETURN_MESSAGE: ""
},
NUM_RECORDS: 0,
START_RECORD: 0,
END_RECORD: 0,
CUSTOMERS: [new Customer()]
};
然后在< script src =“ customers.js” />中引用此文件.
要么
///< reference path =“ customer.js” />在另一个JS文件中.
看看智能感知如何正确显示摘要,但是对于数组,什么也没有.
var custList = new CustomerList();
custList.CUSTOMERS // intellisense
custList.CUSTOMERS[0] // no intellisense as you already know