前端注释规范jsDoc
<p><strong>首先官网地址:<a href="https://jsdoc.bootcss.com/index.html">https://jsdoc.bootcss.com/index.html</a></strong></p>
<p>这是我介绍一下前端注释规范:</p>
<p>这是一个无参数的函数的声明 可以这么写</p>
<pre><code class="language-javascript">/** This is a description of the foo function. */
function foo() {
}</code></pre>
<p>有参数函数声明注释</p>
<pre><code class="language-javascript">/**
* Represents a book.
* @constructor
* @param {string} title - The title of the book.
* @param {string} author - The author of the book.
* @return {Promise&lt;boolean&gt;}
*/
function Book(title, author) {
}
</code></pre>
<p>如果这个函数使用有歧义或者比较复杂可以这些写注释-指定@example</p>
<pre><code class="language-javascript">/**
* @author 什么当当当啊?
* @description list 数据结构 转换成 树结构
* @param {Array} data 需要转换的数据
* @param {String} id 节点 id
* @param {String} pid 父级节点 id
* @param {String} child 子树为节点对象的某个属性值
* @param {Object} labels 需要新增的字段名集合 { label: &#039;category_name&#039; }
* @return {Array}
*
* @example
* formatListToTree({data: [{id:1}, {id: 2}, {id: 3, pid: 1}]})
* =&gt;
* [ { id: 1, children: [ {id: 3, pid: 1} ] }, { id: 2 } ]
*/
function formatListToTree({
data = [],
id = &quot;id&quot;,
pid = &quot;pid&quot;,
child = &quot;children&quot;,
labels = null
}) {
...
}
</code></pre>
<ul>
<li>@author 该类/方法的作者。</li>
<li>@description 该类/方法的描述。</li>
<li>@param 该类/方法的参数,可重复定义。</li>
<li>@return该类/方法的返回类型。</li>
<li>@example 创建例子。</li>
</ul>