-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
你不知道的 console 命令 #4741
你不知道的 console 命令 #4741
Conversation
不局限于 console.log()
@Pomelo1213 文章标题能不能根据文章内容扩充下呢 |
|
校对者校对的时候,看一下是否能提供更好的标题。例如 除了 console.log,我们还可以怎么调试 JavaScript |
@leviding 校对认领 |
@RicardoCao-Biker 好的呢 🍺 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leviding @Pomelo1213 校对完成
TODO1/beyond-console-log.md
Outdated
|
||
# Beyond console.log() | ||
# 不局限于 console.log() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不局限于 console.log() => 你不知道的 console 命令
TODO1/beyond-console-log.md
Outdated
|
||
## There is more to debugging JavaScript than console.log to output values. It might seem obvious I’m going to pimp the debugger, but actually no. | ||
## 相比使用 console.log 去输出值,我们有更多的方式去调试 JavaScript 。看似我要去闲扯调试器,实则不然。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「看似我要去闲扯调试器,实则不然。」 => 「你以为我要聊调试器么?不不不你想错了。」
TODO1/beyond-console-log.md
Outdated
|
||
 | ||
|
||
It seems like it’s cool to tell people doing JavaScript that they should be using the browser’s debugger, and there’s certainly a time and a place for that. But a lot of the time you just want to see whether a particular bit of code executes or what a variable is, **without** disappearing into the RxJS codebase or the bowels of a Promise library. | ||
告诉写 JavaScript 的人应该使用浏览器的调试器,这看来很不错,并且肯定有其适用的时间和场合。但是大多数时候你仅仅只想查看一段特定的代码是否执行或者一个变量的值是什么,而不是迷失在 RxJS 代码库或者一个 Promise 库的深处。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「应该使用浏览器的调试器」 =>「应该使用浏览器的调试器去调试代码」
TODO1/beyond-console-log.md
Outdated
|
||
More than that, there’s another format: `console.log(msg, values)`. This works a lot like something like `sprintf` in C or PHP. | ||
不止那些,这儿还有另一种格式:`console.lo(msg, values)`。这个执行方式和 C 或者 PHP 的`sprintf`很相似。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.lo 少打了字母
TODO1/beyond-console-log.md
Outdated
|
||
### console.log() | ||
|
||
There is a surprising amount of functionality in good old console.log that people don’t expect. While most people use it as `console.log(object)`, you can also do `console.log(object, otherObject, string)` and it will log them all out neatly. Occasionally handy. | ||
标准的 console.log 有着惊人数量的函数特性,这些是人们没有预料到的。尽管多数人将它作为 `console.log(object)` 使用,但你仍然能写 `console.log(object, otherObject, string)` 并且它会将所有东西都整齐的打印出来。有时候确实很方便。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「标准的 console.log 有着惊人数量的函数特性,这些是人们没有预料到的」 =》 「人们不知道 console.log 其实有丰富的函数特性」
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RicardoCao-Biker 这里的good old 不做翻译吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pomelo1213 「很多人不知道经典的 console.log 其实有着丰富的函数特性」
TODO1/beyond-console-log.md
Outdated
|
||
The output from `console.table(data)` though, is a lot more helpful. | ||
然而更有用的是 `console.table(data)` 的输出。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「然而更有用的是 console.table(data)
的输出」 =》 「而 console.table(data)
的输出则对我们更为有帮助」
TODO1/beyond-console-log.md
Outdated
|
||
 | ||
|
||
The optional second argument is the list of columns you want. Obviously defaults to all columns, but we can also do this. | ||
第二个参数选项是你想要显示列表的某列。默认是整个列表,但是我们也能这样做。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「第二个参数选项」 =》 「第二个可选参数」
TODO1/beyond-console-log.md
Outdated
|
||
Sometimes we want more complex conditionals. For example, we’ve seen issues with the data for user `WAL0412` and want to display out only transactions from them. This is the intuitive solution. | ||
有时我们想要更加复杂的场景。举个例子,我们看到了关于用户 `WAL0412` 的数据问题并且想要只展示来自它们的事务。这是直接的解答方式。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「这是直接的解答方式。」 =》 「这将会是一个使用非常简便的方案」
TODO1/beyond-console-log.md
Outdated
|
||
Like a few of these, `console.assert()` isn’t always particularly useful. But it can be an elegant solution in specific cases. | ||
诸如此类,`console.assert()` 并不总是特别的有用。但是在特定的场景下会是最优雅的的解决方法。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「并不总是特别的有用」 =》「并不是一直都很管用」
TODO1/beyond-console-log.md
Outdated
|
||
### console.count() | ||
|
||
Another one with a niche use, count simply acts as a counter, optionally as a named counter. | ||
Count 仅仅作为一个计数器,另一个小众 的用法是,还可选的命名这个计数器。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
「Count 仅仅作为一个计数器,另一个小众 的用法是,还可选的命名这个计数器。」=》 「另外一个合适的用法是,将console作为一个计数器使用」
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RicardoCao-Biker 这里我觉得不太对
校对认领 |
@CoderMing 妥妥哒 🍻 |
TODO1/beyond-console-log.md
Outdated
|
||
Nevertheless, while `console.log` has its place, a lot of people don’t realise that the `console` itself has a lot of options beyond the basic `log`. Appropriate use of these functions can make debugging easier, faster, and more intuitive. | ||
然而,尽管 `console.log` 有其适用的场合,大多数人仍然没有意识到`console`本身除了基础 `log` 还有许多选择。合理使用这些方法能让调试更简单,更快速,并且更加直观。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
大多数人仍然没有意识到console
本身除了基础 log
还有许多选择。 => 但大多数人仍然没有意识到console
本身除了基础 log
方法外还有许多选择。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
合理使用这些方法能让调试更简单,更快速,并且更加直观。 => 合理使用这些方法能让调试更简单、更快速,并且更加直观。
TODO1/beyond-console-log.md
Outdated
|
||
### console.log() | ||
|
||
There is a surprising amount of functionality in good old console.log that people don’t expect. While most people use it as `console.log(object)`, you can also do `console.log(object, otherObject, string)` and it will log them all out neatly. Occasionally handy. | ||
很多人不知道经典的 console.log 其实有着丰富的函数特性。尽管多数人将它作为 `console.log(object)` 使用,但你仍然能写 `console.log(object, otherObject, string)` 并且它会将所有东西都整齐的打印出来。有时候确实很方便。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
尽管多数人将它作为 console.log(object)
使用 => 尽管大多数人只使用 console.log(object)
这种语法
TODO1/beyond-console-log.md
Outdated
|
||
### console.warn() | ||
|
||
Probably the most obvious direct replacement for `log()`, you can just use `console.warn()` in exactly the same way. The only real difference is the output is a bit yellow. Specifically the output is at a warning level not an info level, so the browser will treat it slightly differently. This has the effect of making it a bit more obvious in a cluttered output. | ||
可能是 `log()` 最直接明显的替换,你可以用相同的方式使用 `console.warn()`。唯一的区别在于输出是一抹黄色。确切的说,输出是一个 warn 级别而不是一个 info 级别,因此浏览器的处理稍稍有些不同。在一堆杂乱的输出中高亮你的输出是很有效果的。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
输出是一个 warn 级别而不是一个 info 级别 => 输出是一个 warn 级别而不是一个 info 级别的信息
TODO1/beyond-console-log.md
Outdated
|
||
 | ||
|
||
Something to note here is that this is out of order — the arrow on the far right column header shows why. I clicked on that column to sort by it. Very handy for finding the biggest or smallest of a column, or just getting a different look at the data. That functionality has nothing to do with only showing some columns, by the way. It’s always available. | ||
值得一提的是在最右一列头部的右上角有个箭头可以颠倒次序。点击了它,会排序整个列。非常方便的找出一列的最大或者最小值,或者只是得到不同的数据展示形式。这个功能特性并没有做什么,只是对列的展示。但那总是有用的。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但那总是有用的。 => 但总会是有用的。
TODO1/beyond-console-log.md
Outdated
|
||
### console.assert() | ||
|
||
A function whose usefulness is often missed, `assert()` is the same as `log()` but only in the case where the first argument is _falsey_. It does nothing at all if the first argument is true. | ||
一个经常被忽视的实用的函数,`assert()` 在第一个参数是**假值**时和 `log()` 一样。当第一个参数为真值时也什么都不做。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
假值这块建议不翻译,falsy 在国内的各类文章中都没有被翻译,参考 YDKJS https://github.com/getify/You-Dont-Know-JS/blob/1ed-zh-CN/types%20%26%20grammar/ch4.md
@Pomelo1213 有空的时候修改下吧 |
@Pomelo1213 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。 掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件。 |
不局限于 console.log()
译文翻译完成,resolve #4717