I created the following javascript object:
我创建了以下javascript对象:
var Content = Content || {};
// Constructor defines properties and inits object
Content.ProductManager = function () {
// ...
};
Content.ProductManager.prototype = function () {
//
// private members
//
var setProductAsPreviewed = function (args) {
// code omitted for brevity
// ....
};
//
// public members
//
return {
setProductAsPreviewed: setProductAsPreviewed
};
} ();
The object passed to setProductAsPreviewed
has the following properties:
传递给setproductaspreview的对象具有以下属性:
args = {
productId: int,
productName: string,
updateDate: date,
saveItems: bool
};
I want to include XML comments so I can get intellisense for the argument passed to function setProductAsPreviewed
:
我想要包含XML注释,这样我就可以获得传递给函数setproductaspreview的参数的intellisense:
var productManager = new window.Content.ProductManager();
// show intellisense when typing the following:
productManager.setProductAsPreviewed(
This thread shows how to do it for simple args (string
, int
, ...), but how to do it for a complex object? I'm using Visual Studio 2010.
这个线程展示了如何对简单的args (string, int,…)进行操作,但是如何对复杂的对象进行操作呢?我用的是Visual Studio 2010。
21
As far as I know, you can't tell IntelliSense what fields and methods are on a generic variable if it is being used as a parameter.
就我所知,如果一个泛型变量被用作参数,您就不能告诉IntelliSense在一个泛型变量上有哪些字段和方法。
If the variable was an array, you could define it like this:
如果变量是数组,可以这样定义:
function funcWithArrayArg(arrayArg) {
/// <param name="arrayArg" type="Array" elementType="Number">An array of numbers</param>
}
In VS2012 you can annotate objects as well, like so (you can annotate fields on functions used as object constructors, as I demonstrate below but the docs say nothing about anonymous objects like this):
在VS2012中,您也可以对对象进行注释,比如这样(您可以对作为对象构造函数的函数进行注释,正如我在下面演示的那样,但是文档中没有提到这样的匿名对象):
var args = {
/// <field type="Number">Product ID</field>
productID: int
};
Neither of these approaches really do what you want, as the second approach wouldn't give you intellisense on the function argument and you're using VS2010 anyway.
这两种方法都不是你想要的,因为第二种方法不会给你函数参数的智能感知,而且你也在使用VS2010。
I think your best bet is to define a custom object to be used as an argument object just for that function, after all this is how you would do it in other languages if you wanted to create a custom object as a parameter with intellisense. It might look something like this:
我认为最好的方法是定义一个自定义对象,作为一个参数对象来使用这个函数,毕竟如果你想创建一个自定义对象作为一个具有intellisense的参数,你可以用其他语言来实现。它可能是这样的:
function ProductPreviewArgs(productId, productName, updateDate, saveItems) {
/// <summary>Creates an object for use as the sole argument to the setProductAsPreviewed function</summary>
/// <param name="productId" type="Number" optional="false">The Product ID</param>
/// <param name="productName" type="String" optional="false">The Product Name</param>
/// <param name="updateDate" type="Date" optional="false">The date the product was last updated</param>
/// <param name="saveItems" type="Boolean" optional="false">Specifies whether or not to save the items</param>
/// <returns type="ProductPreviewArgs">An object intended for use as the sole argument to the setProductAsPreviewed function</returns>
/// <field name="productId" type="Number">The Product ID</field>
/// <field name="productName" type="String">The Product Name</field>
/// <field name="updateDate" type="Date">The date the product was last updated</field>
/// <field name="saveItems" type="Boolean">Specifies whether or not to save the items</field>
this.productId = productId;
this.productName = productName;
this.updateDate = updateDate;
this.saveItems = saveItems;
}
You would get intellisense on the object (which will show what you have put in the returns
element) here:
你可以在这个对象上获得智能感知(它会显示你在return元素中添加了什么):
setProductAsPreviewed(
If you then decide to create a new object, you would get IntelliSense here (which will show you the descriptions for each parameter one by one as you add them):
如果您决定创建一个新对象,您将在这里获得IntelliSense(它将在您添加每个参数时逐一显示它们的描述):
setProductAsPreviewed(new ProductPreviewArgs(
I'm not entirely sure whether the type
attribute on the returns
element will actually work like that, it does in VS2012 and as you might have come to expect by now, the docs are annoyingly bare on this subject; and I don't have a copy of VS2010 to test any of this on right now.
我不完全确定return元素的type属性是否会这样工作,它在VS2012中会这样工作,正如您现在可能已经预料到的那样,文档在这个主题上是令人恼火的;我现在没有VS2010的拷贝来测试这些。
6
You can create a separate IntelliSense file, that looks something like this
您可以创建一个单独的IntelliSense文件,它看起来是这样的
intellisense.annotate(Content, {
'setProductAsPreviewed ': function() {
/// <signature>
/// <summary>Summary<summary>
/// <param name="args" type="ComplexObject">some text here
/// </signature>
}
})
I believe this should work with some modification
我认为这应该可以做一些修改
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2013/05/23/7dc7a7be7bfd2b41b961afd8db0ca15c.html。