2021-11-08vscode中console.log的两种快速写法

(一)方法一:直接在script标签中提前定义,仅适用于该html文件!

 let add = function(a,b){
     return a + b;
 };
 console.log(add(20,300));
 
 const { ['log']:C } = console;
 C(add(20,300));

(二)方法二:按tab键快速生成console.log,且光标在()内部,再次按tab键光标自动跳转到下一行!
1、打开vscode编辑器,选择文件->首选项->用户片段,输入javascript.json并按下enter进入。
初次使用我们会发现一段被注释的代码如下:

{
    // Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    // "Print to console": {
    //     "prefix": "log",
    //     "body": [
    //         "console.log('$1');",
    //         "$2"
    //     ],
    //     "description": "Log output to console"
    // }

2、解除Example以下的区间代码如下,其中部分参数意义如下:
①prefix:代码快捷键的入口,在这里我们根据个人习惯进行设置即可,如我设置的cl,那么配合tab健就可以直接生成console.log;
②body表示代码主体:
$1表示生成代码快速生成后后光标首次出现的位置
$2写在"console.log(’$1’);"下面,表示在快速生成console.log()后,代码后会空出一行,并且再次按tab键时,光标会跳转到$2(空出的一行)的位置

{
    // Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    "Print to console": {
        "prefix": "cl",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log output to console"
    }
}
————————————————
版权声明:本文为CSDN博主「时光-ing」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/blbyu/article/details/121188926

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值