在Chrome中创建console.log()的快捷方式 [英] Create shortcut to console.log() in Chrome

查看:480
本文介绍了在Chrome中创建console.log()的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我很懒,我创建了一个函数 log ,基本上只是 console.log

Because I'm lazy, I created a function log that basically is just an abbreviation of console.log:

function log() {
  console.log.apply(console, arguments);
}

无论何时调用此项,我都会在Google Chrome的开发人员工具中看到记录的项目,其右侧是记录项目的行号。然而,这个行号总是相同的,因为实际的 console.log 调用位于代码中的一个特定位置(即我声明 log function as above)。

Whenever I call this, I see the logged item in Google Chrome's Developer Tools, with on the right hand side the line number where the item was logged. However, this line number is always the same, because the actual console.log call is located at one specific place in the code (namely where I declare the log function as above).

我还试过的只是:

var log = console.log;

但这总是会引发错误:非法调用。很奇怪,但我想这不是一个可能性。

but this always throws an error: Illegal invocation. Weird, but I guess that's not a possibility.

如何快速创建 console.log 显示 log 的行号的开发工具被调用,而不是实际的 console.log 调用的位置? / p>

How can I make a shortcut to console.log, with Developer Tools showing the line number where log was called, rather than where the actual console.log call is located?

推荐答案

当我报告它,它被拒绝,但答案很简单 - 创建如下快捷方式:

When I reported it, it was refused but the answer was simple - create the shortcut like this:

var log = console.log.bind(console);

这不会留下行号,而您可以像 log(...)

This doesn't leave out the line number, whilst you can call it like log(...).

这篇关于在Chrome中创建console.log()的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆