鉴于面向对象层次结构的模型过于简单:
var BaseObj = function (field) { this.field = field; };
var DescendentObject = function (field, field2) {
this.BaseObj(field);
this.field2 = field2;
};
BaseObj.prototype = {
///<field name="field" type="String">I am well documented</field>
field : ""
};
DescendentObject.prototype = {
///<field name="field" type="String">I am well documented</field>
field2 : ""
};
//this simplies our actual inheritance model but effectively does the same thing
DescendentObject.prototype.BaseObj = BaseObj;
DescendentObject.prototype.field = BaseObj.prototype.field;
var x = new DescendentObject();
x.field2 //I am well documented
x.field //editor knows I exist, but I am completely undocumented!
有没有办法将BaseObj中字段的优秀文档放入DescendentObject中的字段,而无需显式列出两个对象中的每个字段?
答案 0 :(得分:0)
你可以把put实例intellisense放在BaseObj
上var BaseObj = function (field) {
///<field name="field" type="String">I am well documented</field>
this.field = field;
};
或使用非对象文字符号:
DescendentObject.prototype = new (function(){
/// <field name="field" type="String">I am well documented</field>
this.field2 = "";
})();
根据此处的文件:http://msdn.microsoft.com/en-us/library/hh542725.aspx, 此注释忽略name属性并自动附加到其下面的任何内容,因为它位于对象文字内:
DescendentObject.prototype = {
///<field name="field" type="String">I am well documented</field>
field2 : ""
};