vs code配置js模板

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",

        "}"

    ]

}

}

了解更多内容 关注公众号
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值