Visual Studio Intellisense を利用したいので、以下を読みました:
http://msdn.microsoft.com/en-us/library/bb514138.aspx
とにかく、なぜ私はインテリセンスを取得しないのですか:
function Customer() {
this.Id = 0;
this.FirstName = "";
this.LastName = "";
}
function Test() {
/// <returns type="Customer"></returns>
var c = new Object();
$.ajax({
async: false,
dataType: "json",
url: "Ajax/GetCustomer.aspx",
success: function (foundCustomer) {
// I know that found customer is of type Customer
c = foundCustomer;
}
});
return c;
}
var x = Test();
x. // No intellicense! why?
関数が TYPE のオブジェクトを返すことを Visual Studio に知らせるにはどうすればよいCustomer
ですか? たとえば、関数 Test for: を置き換えるfunction Test(){ return new Customer(); }
と、intellicense が機能します。
編集
最後の私の目標は、次のようなものにすることです。
function Customer() {
this.Id = 0;
this.FirstName = "";
this.LastName = "";
}
Object.prototype.CastToCustomer = function(){
/// <returns type="Customer"></returns>
return this;
}
$.ajax({
async: false,
dataType: "json",
url: "Ajax/GetCustomer.aspx",
success: function (foundCustomer) {
foundCustomer = foundCustomer.CastToCustomer();
foundCustomer.// Intellicense does not work :(
}
});
多くの json オブジェクトを取得し、このヘルパー関数を使用してそれらをキャストしたいと考えています。
一時的な解決策:
これは私がやったことです:
function Customer() {
this.Id = 0;
this.FirstName = "";
this.LastName = "";
}
$.ajax({
async: false,
dataType: "json",
url: "Ajax/GetCustomer.aspx",
success: function (foundCustomer) {
// this will never be true on real browser. It is always true in visual studio (visual studio will now think that found customer is of type Customer ;)
if (document.URL.length == 0) foundCustomer = new Customer();
foundCustomer.// Intellisense works!!!!
}
});