How do you get VS 2008 Javascript Intellisense working for complex prototypes?

I managed to get javascript intellisense to work correctly for a prototype class defined as follows:

function GetCustomerList()
{
}

GetCustomerList.prototype = 
{
    HEADER: {
        RETURN_CODE: 0,
        RETURN_MESSAGE: "",
        }
    ,
    NUM_RECORDS: 0,
    START_RECORD: 0,
    END_RECORD: 0
};

I can print something like:

var req = new GetCustomerList();
req.HEADER.RETURN_CODE = 100;

And Visual Studio intellisense knows about the HEADER property and its own properties with the names "RETURN_CODE" and "RETURN_MESSAGE". I can do:

req.NUM_RECORDS = 50;

With perfect intellisense work.

So intellisense works with complex nested types - great. However, is it possible to get intellisense with an array of complex types?

Example:

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() ]
};

Where I have an array of type "CUSTOMER", for which I also defined a prototype. I would like to be able to introduce things like:

req.CUSTOMER[ 0 ].NAME 

And ask intellisense to indicate that "NAME" is a property available for this array.

?

+3
3

UPDATE:

, IntelliSense , . , String, .

, , . javascript "clients.js" :

function Customer() {
    /// <summary>This is my custom intellisense for the Customer type</summary>
    ///<field name="NAME" type="String">The Customer name</field>
    ///<field name="ADDRESS" type="String">The customer 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 .

, intellisense , , .

var custList = new CustomerList();

custList.CUSTOMERS // intellisense
custList.CUSTOMERS[0] // no intellisense as you already know
+3

VS2008. VS.

0

VS , .

script :

function Customer(obj) {
    /// <summary>This is my custom intellisense for the Customer type</summary> 
    ///<field name="NAME" type="String">The Customer name</field> 
    ///<field name="ADDRESS" type="String">The customer address</field>
    ///<field name="ID" type="String">The ID number</field>
    if (obj) return obj;
}

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: ''
    },
    CUSTOMERS: []
}; 

(Note the change to the constructor - not sure about the XML comment for intellisense).

Then you can reference it like this (using intellisense):

var list = new CustomerList();

var cust = new Customer();
cust.NAME = 'john';
list.CUSTOMERS.push(cust);

var cust1 = new Customer(list.CUSTOMERS[0]);
alert(cust1.NAME);

var cust2 = new Customer({ NAME: 'Mark' });
alert(cust2.NAME);

The argument against this is that you need a parameter in the constructor.

0
source

Source: https://habr.com/ru/post/1706603/


All Articles