-
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
在 JSX 代码中可以加入 console.log 吗? #5288
在 JSX 代码中可以加入 console.log 吗? #5288
Conversation
校对认领 @fanyijihua |
@noahziheng 好的呢 🍺 |
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.
Great! 一些小的流畅性方面的建议,供参考。
校对完成 @EmilyQiRabbit @leviding
TODO1/can-you-console-log-in-jsx.md
Outdated
|
||
![](https://cdn-images-1.medium.com/max/2000/1*OIfGKWZBZRsvKQZxQtr3Yw.jpeg) | ||
|
||
As a coding instructor, I have seen many students trying 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/can-you-console-log-in-jsx.md
Outdated
@@ -24,13 +24,13 @@ render() { | |||
} | |||
``` | |||
|
|||
This will not print the expected list in the console. It will just render the string *console.log(this.props.todos)* in the browser. | |||
这样写不会在控制台打印出期望的内容。而是在浏览器上渲染出 **console.log(this.props.todos)** 字符串。 |
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/can-you-console-log-in-jsx.md
Outdated
|
||
Let’s first take a look at some solutions which are very straightforward, then we will explain the reason. | ||
我们先来看一些很直观的解决方案,然后我们将会解释原因。 |
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.
「原因」=>「原理」
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/can-you-console-log-in-jsx.md
Outdated
|
||
Ultimately, JSX gets compiled into vanilla JavaScript. | ||
最后,JSX 会被编译成原生 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.
「最后,JSX 会被编译成原生」=>「最终,JSX 将会被编译成原生」
TODO1/can-you-console-log-in-jsx.md
Outdated
|
||
Let’s now review the failing console.log that we tried to write at the start of this article: | ||
我们现在来回顾一下文章开始的时候写的运行失败的 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/can-you-console-log-in-jsx.md
Outdated
|
||
* `'h1'`: This is the name of the tag, as a string | ||
* `'h1'`:它是标签名,是一个字符串类型 |
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/can-you-console-log-in-jsx.md
Outdated
|
||
* `{ className: 'greeting' }`: These are the props used in `<h1>` . It is converted to an object. The key of the object is the name of the prop and the value, its value. | ||
* `{ className: 'greeting' }`:它是 `<h1>` 的属性。它会被转换成一个对象。对象的键就是属性名,对象的键值就是属性的值。 |
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/can-you-console-log-in-jsx.md
Outdated
|
||
```jsx | ||
// when more than 1 thing is passed in, it is converted to an array | ||
// 当多于一个元素被传递进去,第三个参数将会变成一个数组 |
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/can-you-console-log-in-jsx.md
Outdated
'List of todos', | ||
), | ||
'console.log(this.props.todos)' | ||
] | ||
); | ||
``` | ||
|
||
See how the `console.log` is passed as a string to `createElement`. It is not executed. | ||
`console.log` 被当成一个数组传递到了方法 `createElement`。它并没有被执行。 |
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 校对认领 |
@hanxiansen 妥妥哒 🍻 |
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.
翻译得很好,提了一点小建议。
@EmilyQiRabbit @leviding 校对完成
TODO1/can-you-console-log-in-jsx.md
Outdated
|
||
Let’s first take a look at some solutions which are very straightforward, then we will explain the reason. | ||
我们先来看一些很直观的解决方案,然后我们将会解释原因。 |
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/can-you-console-log-in-jsx.md
Outdated
|
||
We have to remember that JSX is not vanilla JavaScript, nor is it HTML. It is a syntax extension. | ||
我们必须记住,JSX 不是原生的 JavaScript,也不是 HTML。它是一种语法扩展。 |
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.
「我们必须记住,」 =>「我们必须记住:」
@noahziheng @hanxiansen 感谢校对 |
@leviding 修改完成 |
@EmilyQiRabbit 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。 掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件。 |
译文翻译完成,resolve #5262