将子属性添加到jsdoc中的现有属性列表 [英] Adding sub-properties to an existing property-list in jsdoc

查看:143
本文介绍了将子属性添加到jsdoc中的现有属性列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使我们的JS库中的特定模块自动化,并停留在要定义一组属性的位置(让我们说一个对象作为类的构造参数).

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).

/**
 * 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.

如何添加到先前为WorldPeace函数定义的原始属性集?进行诸如mixin之类的操作或对属性进行子类化将太过分了!这样,如果我可以简单地注入一个属性列表定义,那就太好了.

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.

推荐答案

另一种方法是使用typedef:

Another way to do it would be to use a typedef:

/** 
 * @typedef {{
 *   issues: number,
 *   source: string
 * }}
 */
var WorldPeaceOptions;

/**
 * @constructor
 * @param {WorldPeaceOptions} defaults
 */
var WorldPeace = function (defaults) {
  // code here
};

这篇关于将子属性添加到jsdoc中的现有属性列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆