1、操作
vs code中,选择文件/首选项/用户代码片段,在弹出的界面中,搜索javascript,并选中
将附件javascript.json的内容粘贴到打开的页签中,保存
vs code中新建一个空白的js文件,输入jscommont,将自动生成js模板
2、注意
关键字jscommont,可以在模板javascript.json中修改
可以按照规范,编辑js模板文件
3、效果
生成的模板,如附件“js规范模板生成文件.js”所示,如下图
============分割线,下面是模板的编辑内容=============
{
"js template": {
"prefix": "jscommont",
"body":[
"/**",
" * @description Create a point.",
" * @copyright ***有限公司 2019 (http://www.***.com/)",
" * @version V1.0",
" * @date 2019-09-20",
" * @author XXX",
" */\n",
"// 常量定义",
"const PI = 3.1415;\n",
"// 点到原点的距离",
"let distancePointToOrigin = 0;\n",
"/**",
" * @description 定义Point类",
" * @class: Point",
" */",
"export default class Point {",
" /**",
" * @description Create a point.",
" * @param {number} x - The x value.",
" * @param {number} y - The y value.",
" */",
" constructor(x, y) {",
" this.x = x;",
" this.y = y;",
" }\n",
" /**",
" * Set the x value.",
" * @param {number} x - The x value.",
" */",
" setX = x => {",
" // Here should check the x value.",
" this.x = x;",
" }\n",
" /**",
" * Get the x value.",
" * @return {number} The x value.",
" */",
" getX = () => {",
" return this.x;",
" }\n",
" /**",
" * Change the Point object to a string.",
" * @return {string} The string value like '(1, 2)'.",
" */",
" toString() {",
" return `(${this.x}, ${this.y})`;",
" }\n",
" /**",
" * Measure if the point is the origin.",
" * @return {boolean} true or false.",
" */",
" isOrigin() {",
" if (this.x === 0 && this.y === 0) {",
" return true;",
" } else {",
" return false;",
" }",
" }\n",
"}"
]
}
}