在 Chrome 中创建 console.log() 的快捷方式 [英] Create shortcut to console.log() in Chrome
问题描述
因为我很懒,所以创建了一个函数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
函数的位置).
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;
但这总是抛出一个错误:Illegal invocation
.很奇怪,但我想这不可能.
but this always throws an error: Illegal invocation
. Weird, but I guess that's not a possibility.
如何创建 console.log
的快捷方式,让开发者工具显示调用 log
的行号,而不是实际 控制台的行号.记录
调用定位?
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屋!