详解vscode中console.log的两种快速写法 - 网站

详解vscode中console.log的两种快速写法

分类:JavaScript进阶教程_JavaScript技术文章 · 发布时间:2023-11-12 01:10 · 阅读:6429

这篇文章主要介绍了vscode中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" } } 

到此这篇关于vscode中console.log的两种快速写法的文章就介绍到这了,更多相关vscode console.log写法内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

标签:
vscode console.log

相关文章

一起来学习TypeScript的类型

这篇文章主要为大家详细介绍了TypeScript的类型,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下,希望能够给你带来帮助

JavaScript去除字符串两端空格的三种方法

本文主要介绍了JavaScript去除字符串两端空格的三种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

html2canvas图片跨域问题图文详解

我们在进行图片保存的时候经常会发现图片跨域了,下面下面这篇文章主要给大家介绍了关于html2canvas图片跨域问题的相关资料,需要的朋友可以参考下

JavaScript中Set基本使用方法实例

因为Set中存放的数据都是不会重复的数据,我们在编写JS代码的时候,因此我们可以利用Set来帮助我们更便捷地完成许多的事,下面这篇文章主要给大家介绍了关于JavaScript中Set基本使用方法的相关资料,需要的朋友可以参考下

JavaScript基础之运算符与表达式详解

这篇文章主要为大家详细介绍了JavaScript中一些常见的运算符与表达式的具体使用,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起了解一下

返回分类 返回首页