Skip to content
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

Merged

Conversation

EmilyQiRabbit
Copy link
Contributor

译文翻译完成,resolve #5262

@EmilyQiRabbit EmilyQiRabbit changed the title Update can-you-console-log-in-jsx.md 在 JSX 代码中可以加入 console.log 吗? Mar 1, 2019
@noahziheng
Copy link
Contributor

校对认领 @fanyijihua

@fanyijihua
Copy link
Collaborator

@noahziheng 好的呢 🍺

Copy link
Contributor

@noahziheng noahziheng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 一些小的流畅性方面的建议,供参考。
校对完成 @EmilyQiRabbit @leviding


![](https://cdn-images-1.medium.com/max/2000/1*OIfGKWZBZRsvKQZxQtr3Yw.jpeg)

As a coding instructor, I have seen many students trying this:
作为一名编程老师,我曾看到过我的学生尝试这样写代码:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「尝试这样写代码」=>「写出了这样的代码」

@@ -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)** 字符串。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「字符串」=>「这个字符串」


Let’s first take a look at some solutions which are very straightforward, then we will explain the reason.
我们先来看一些很直观的解决方案,然后我们将会解释原因。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「原因」=>「原理」

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「直观」=>「直接」

看了下后面的解觉方案,感觉都是那种很直截了当的方法,感觉翻译为“直接”会不会更符合语境。


Ultimately, JSX gets compiled into vanilla JavaScript.
最后,JSX 会被编译成原生 JavaScript
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「最后,JSX 会被编译成原生」=>「最终,JSX 将会被编译成原生」


Let’s now review the failing console.log that we tried to write at the start of this article:
我们现在来回顾一下文章开始的时候写的运行失败的 console.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「运行失败」=>「失败」
没有运行报错啥的,只是和预想不一致的结果


* `'h1'`: This is the name of the tag, as a string
* `'h1'`:它是标签名,是一个字符串类型
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去除「它是」


* `{ 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>` 的属性。它会被转换成一个对象。对象的键就是属性名,对象的键值就是属性的值。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去除「它是」


```jsx
// when more than 1 thing is passed in, it is converted to an array
// 当多于一个元素被传递进去,第三个参数将会变成一个数组
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「多于一个」=>「一个以上的」

'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`。它并没有被执行。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「被当成一个数组」=>「被当成一个字符串」

@henry-fun
Copy link
Contributor

@leviding 校对认领

@fanyijihua
Copy link
Collaborator

@hanxiansen 妥妥哒 🍻

Copy link
Contributor

@henry-fun henry-fun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

翻译得很好,提了一点小建议。
@EmilyQiRabbit @leviding 校对完成


Let’s first take a look at some solutions which are very straightforward, then we will explain the reason.
我们先来看一些很直观的解决方案,然后我们将会解释原因。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「直观」=>「直接」

看了下后面的解觉方案,感觉都是那种很直截了当的方法,感觉翻译为“直接”会不会更符合语境。


We have to remember that JSX is not vanilla JavaScript, nor is it HTML. It is a syntax extension.
我们必须记住,JSX 不是原生的 JavaScript,也不是 HTML。它是一种语法扩展。
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「我们必须记住,」 =>「我们必须记住:」

@leviding leviding added the enhancement 等待译者修改 label Mar 1, 2019
@EmilyQiRabbit
Copy link
Contributor Author

@noahziheng @hanxiansen 感谢校对

@EmilyQiRabbit
Copy link
Contributor Author

@leviding 修改完成

@leviding leviding added 标注 待管理员 Review and removed enhancement 等待译者修改 labels Mar 2, 2019
@leviding leviding merged commit 8ffaa74 into xitu:master Mar 2, 2019
@leviding
Copy link
Member

leviding commented Mar 2, 2019

@EmilyQiRabbit 已经 merge 啦~ 快快麻溜发布到掘金然后给我发下链接,方便及时添加积分哟。

掘金翻译计划有自己的知乎专栏,你也可以投稿哈,推荐使用一个好用的插件
专栏地址:https://zhuanlan.zhihu.com/juejinfanyi

@leviding leviding added 翻译完成 and removed 标注 待管理员 Review 正在校对 labels Mar 2, 2019
@EmilyQiRabbit EmilyQiRabbit deleted the translation/can-you-console-log-in-jsx branch June 19, 2019 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

在 JSX 代码中可以加入 console.log 吗?
5 participants