Create Javascript Function That Works With Intellisense
I want to take advantage of visual studio intellisense therefore I have read: http://msdn.microsoft.com/en-us/library/bb514138.aspx Anyways why I do not get intellisense with: func
Solution 1:
You are initializing the return value to an Object
so it's on that which the Intellisense is based. If you initialize it to an empty Customer
, then the Intellisense will detect that it is returning a Customer
functionTest() {
var c = newCustomer(); //only for Intellisense
$.ajax({...});
return c;
}
Test(). //Customer members now appear
You can also use /// <param />
to specify the parameter type:
$.ajax({
...
success: function (foundCustomer) {
/// <param name='foundCustomer' type='Customer' />
foundCustomer. //Customer members appear
}
});
Finally, your document.URL.length
trick can also be used in the casting method:
Object.prototype.CastToCustomer = function() {
var c = newCustomer();
if (document.URL.length) c = this;
return c;
}
Solution 2:
If you change your Customer function to accept arguments:
function Customer(opts) {
var opts = opts || {};
this.id = 0;
this.firstName = '';
this.lastName = '';
for (var i in opts) {
if (opts.hasOwnProperty(i)) this[i] = opts[i];
}
}
Then inside your Test
function, change c = foundCustomer
to c = new Customer(foundCustomer)
. I'm guessing this might trigger the intellicense?
Post a Comment for "Create Javascript Function That Works With Intellisense"