$0能夠用來表示當前在Chrome DevTools中的Elements欄中查看頁面信息中選中的html節點css
$在console控制檯中是document.querySelector方法的別名【未定義$的狀況下】,$$則是document.querySelectorAll的方法並將結果以數組的形式返回NodeList類型
$$的做用簡單表示html
Array.from(document.querySelectorAll('div')) === $$('div')
$_ 能夠用在控制檯中做爲上一個值的引用直接使用,節省時間node
Math.random(); // 0.2505550952725395 $_ // 0.2505550952725395
搭配插件Console Importer使用,注意:有些頁面受CSP安全策略影響沒法使用
當須要引入某個庫時,能夠使用$i(npm package name); 好比:$i('lodash');提示成功後,就能夠在控制檯中使用lodash庫提供的方法了npm
DevTools中提供的copy方法能夠用來將控制檯Console中任何存在的東西複製到粘貼板上json
msg = 'asdf'.repeat(3); // asdfasdfasdf copy($_) // asdfasdfasdf
使用console.assert斷言打印自定義信息提示,若是console.assert第一個參數是falsy值則會打印自定義信息數組
value = null; console.assert(value,'Value is empty'); // VM5452:2 Assertion failed: Value is empty
用於將數據按照表格的形式輸出,視覺上更加直觀瀏覽器
console.table(data);
能夠使用console.dir將DOM節點的詳細信息和默認屬性打印出來安全
console.dir(NodeType);
在Console中,要使用async await不用手動包裹一層async,可直接使用await,由於它默認已經加了Async網絡
resp = await fetch('url'); json = await fetch('url');
能夠用來追蹤查看某個屬性或方法被調用dom
class Person { constructor(name, role) { this.name = name; this.role = role; } greet() { return this.getMessage('greeting'); } getMessage(type) { if (type === 'greeting') { return `Hello, I'm ${this.name}!`; } } } j = new Person('Json'); m = new Person('Mary'); monitor(j.getMessage); j.greet(); //function getMessage called with arguments: greeting // "Hello, I'm Json!"
給某個節點添加監聽事件
monitorEvent(nodeReference, eventName);
能夠自定義輸出內容的樣式
console.log('%cHello Console 😸','color:lightblue; font-size:30px') // %c 做爲文本內容的前綴 後面爲輸出內容,第二個參數爲輸出的樣式
通常狀況下咱們使用console.log去打印一些變量或屬性時,只會打印出對應的值,若是不去手動添加對應的key,當內容不少的時候很容易搞混,這時只須要在console.log中加上一對{},就能夠以對象的形式,將內容輸出,固然也能夠使用console.table,使用方法徹底一致,將值以表格的形式打印出來
let name = 'game'; let something = 'limbo'; let anything = 'inside'; let number = 34; console.log(name,something,anything,number); // game limbo inside 34
方法一:
二:
便可以自定義網速,同時在下面一個選項User agent中還能夠自定義UA,也能夠選擇已有的各類瀏覽器UA...
getList(v=>console.log(v)); getList(console.log);