gpt4 book ai didi

javascript - 如何使用 console.log 省略文件/行号

转载 作者:数据小太阳 更新时间:2023-10-29 04:18:02 28 4
gpt4 key购买 nike

如今,您可以在 Chrome 的控制台中编写非常棒的东西。结帐this关联。我也截图了:

enter image description here

正如您在屏幕截图中看到的,文件名/行号 (VM298:4) 写在右侧。是否有可能删除它,因为在我的例子中这是一个很长的名字,或多或少地破坏了我试图在我的控制台中制作的效果?

最佳答案

这很容易做到。您需要将 setTimeoutconsole.log.bind 一起使用:

setTimeout (console.log.bind (console, "This is a sentence."));

如果您想对其应用 CSS 或其他文本,只需添加 %c 或任何其他 % 变量:

setTimeout (console.log.bind (console, "%cThis is a sentence.", "font-weight: bold;"));
var css = "text-decoration: underline;";
setTimeout (console.log.bind (console, "%cThis is a sentence.", css));

请注意,此方法将始终放在日志列表的末尾。例如:

console.log ("Log 1");
setTimeout (console.log.bind (console, "This is a sentence."));
console.log ("Log 2");

将显示为

Log 1
Log 2
This is a sentence.

代替

Log 1
This is a sentence.
Log 2

我希望这能回答您的问题。

关于javascript - 如何使用 console.log 省略文件/行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36009071/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com