跨页面如何保留console消息?

image.png

勾选 Preserve log即可

问题背景

有很多时候我很烦恼这样的问题,比如我在登陆页面打印了一个日志,然后我希望在登陆后的那个页面依然展示我打印的消息

Live Expressions

背景

If you find yourself typing the same JavaScript expression in the Console repeatedly, you might find it easier to create a Live Expression. With Live Expressions you type an expression once and then pin it to the top of your Console. The value of the expression updates in near real-time.

使用

点击这个眼睛即可截屏2020-11-04 下午5.45.14.png
截屏2020-11-04 下午5.45.02.png
截屏2020-11-04 下午5.46.32.png

使用console断言

  1. const x = 5;
  2. const y = 3;
  3. const reason = 'x is expected to be less than y';
  4. console.assert(x < y, {x, y, reason});

如何使用计数器?

console.count()

image.png

如何计算执行时间差?

  1. console.time();
  2. for (var i = 0; i < 100000; i++) {
  3. let square = i ** 2;
  4. }
  5. console.timeEnd();

如何打印堆栈?

  1. const first = () => { second(); };
  2. const second = () => { third(); };
  3. const third = () => { fourth(); };
  4. const fourth = () => { console.trace(); };
  5. first();

截屏2020-11-04 下午2.43.50.png

如何使用上一个返回值?

$_
截屏2020-11-04 下午3.03.21.png

如何快速引用一个元素?

使用鼠标检查元素,然后使用$0 即可引用

可以使用$0 $1 $2 $3分别表示最近检查的4个元素,从近到远
截屏2020-11-04 下午3.19.04.png

如何快速复制一个对象到剪贴板?

copy(object)

截屏2020-11-04 下午4.04.57.png

如何调试一个函数?

debug(fn)

把对象打印成表格?

  1. var names = {
  2. 0: { firstName: "John", lastName: "Smith" },
  3. 1: { firstName: "Jane", lastName: "Doe" }
  4. };
  5. table(names);

截屏2020-11-04 下午5.23.59.png