将子属性添加到jsdoc中的现有属性列表
I am trying to automate a particular module in our JS library and am stuck at a point where I want to define a set of properties (lets say an object that goes as construction parameter of a class).
我试图在我们的JS库中自动化一个特定的模块,并且我想要定义一组属性(假设一个对象作为类的构造参数)。
/**
* This function initiates world peace!
* @constructor
* @param {object} defaults - The options to initiate peace.
* @param {number} defaults.issues - The number of issues being taken up.
* @param {string} defaults.source - The name of the location where process starts.
*/
var WorldPeace = function (defaults) {
// code here
};
It is well and good had all properties of the construction was defined at one location. Unfortunately, my code has a number of modules contributing to that construction properties. Lets say, at some other portion of the code (in a later file) causes to have a couple of more properties
如果在一个地方定义了建筑的所有属性,那就很好了。不幸的是,我的代码有许多模块有助于构造属性。可以说,在代码的某些其他部分(在后面的文件中)导致具有更多属性
* @param {Date} defaults.start - The date when the process started.
* @param {Date} defaults.stop - The date when the process should stop.
How do I go about adding to the original set of properties that I had previously defined for WorldPeace
function? Doing something like a mixin or subclassing the properties would be going overboard! As such, if I can simply inject to a property list definition it would be great.
如何添加我之前为WorldPeace函数定义的原始属性集?做一些像mixin或子类化属性的东西将会过火!因此,如果我可以简单地注入属性列表定义,那就太棒了。
2 个解决方案
#1
1
The easiest method is to use a record type:
最简单的方法是使用记录类型:
/**
* This function initiates world peace!
* @constructor
* @param {{issues: number, source: string}} defaults - options to initiate peace.
*/
var WorldPeace = function (defaults) {
// code here
};
You could also implement an interface:
您还可以实现一个接口:
/** @interface */
var WordPeaceDefaults;
/** @type {number} */
WorldPeaceDefaults.prototype.issues;
/** @type {string} */
WorldPeaceDefaults.prototype.source;
/**
* This function initiates world peace!
* @constructor
* @param {WorldPeaceDefaults} defaults - options to initiate peace.
*/
var WorldPeace = function (defaults) {
// code here
};
/**
* @constructor
* @implements {WorldPeaceDefaults}
*/
function MyWorldPeaceDefaults() {}
/** @type {number} */
MyWorldPeaceDefaults.prototype.issues = 0;
/** @type {string} */
MyWorldPeaceDefaults.prototype.source = '';
WordPeace(new MyWorldPeaceDefaults);
更多相关文章
- AngularJS:TypeError:无法读取未定义的属性'get'?
- 自定义ComboBox焦点不会切换到选择elem并且eventBubble不会停止
- javascript类定义与对象的性能
- 当函数在单独的PHP文件中定义时,调用JavaScript函数onclick按钮事
- python 修改vs工程属性
- MPRIS + Python (dbus):读写属性
- Python中类的使用(5私有属性)
- Python NameError:全局名称“Form”没有定义pyqt
- 'module'对象没有属性'views' django错误