今天就跟大家聊聊有關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的兩種快速寫法分別是什么有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。