注释
... 2020-9-30 About 2 min
# 注释
# 关于代码
// TODO 功能未完成,待完善
// FIXME 待修复
// XXX 实现方法待确认
// NOTE 代码功能说明
// HACK 此处写法有待优化
// BUG 此处有 Bug
1
2
3
4
5
6
2
3
4
5
6
# 关于文件
/*
* 简述当前文件功能
* @author 作者名称
* @version 版本号 最近编辑时间
* @description 该版本改动信息
*/
1
2
3
4
5
6
2
3
4
5
6
# 关于函数
/**
* 方法说明
* @method 方法名
* @for 所属类名
* @param {参数类型} 参数名 参数说明
* @return {返回值类型} 返回值说明
*/
1
2
3
4
5
6
7
2
3
4
5
6
7
# 常用标签
- @type{typeName}
*
表示任何类型- ? 表示可以为 null
- ! 表示不能为 null
- [] 表示数组
eg:
/**
* @type {number}
*/
var foo1;
1
2
3
4
2
3
4
- @param {} name - some description
- 非必传参数需给参数名加上 []
- 参数如有默认值需用 = 表示
- 如果参数是 Object,可继续用 @param 对其属性进行详细说明
- 若干个参数用 ... 表示
eg:
/**
* @func
* @desc 一个带参数的函数
* @param {string} a - 参数a
* @param {number} b = 1 - 参数b默认值为1
* @param {string} c = 1 - 参数c有两种支持的取值 1—表示x 2—表示xx
* @param {object} d - 参数d为一个对象
* @param {string} d.e - 参数d的e属性
* @param {object[]} g - 参数g为一个对象数组
* @param {string} g.h - 参数g数组中一项的h属性
* @param {string} [j] - 参数j是一个可选参数
*/
function foo(a, b, c, d, g, j) {}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 条件注释
一般 IE 的时候使用的比较多
- 只允许 IE 解释执行
<!--[if IE]><![endif]-->
- 只允许 IE 特定版本解释执行
<!--[if IE 7]><![endif]-->
- 只允许非 IE 特定版本执行注释
<!--[if !IE 7]><![endif]-->
- 只允许高于或低于 IE 特定版本执行注释
<!--[if gt IE 7]><![endif]-->
eg:
<head>
<title>IE 条件注释</title>
<!-- 是 IE 时 -->
<!--[if IE
]> <link href="style.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!-- 是 IE 7 时 -->
<!--[if IE 7]>
<link href="style.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!-- 不是 IE 7 时 -->
<!--[if !IE 7]>
<link href="style.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!-- 大于 IE 7 时 -->
<!--[if gt IE 7]>
<link href="style.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!-- 小于 IE 7 时 -->
<!--[if lt IE 7]>
<link href="style.css" rel="stylesheet" type="text/css" />
<![endif]-->
</head>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34