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

TypeScript:拥有超能力的 JavaScript #3386

Merged
merged 7 commits into from Mar 9, 2018
Merged

TypeScript:拥有超能力的 JavaScript #3386

merged 7 commits into from Mar 9, 2018

Conversation

jonjia
Copy link
Contributor

@jonjia jonjia commented Mar 6, 2018

译文翻译完成,resolve #3365

@moods445
Copy link

moods445 commented Mar 6, 2018

校对认领 @fanyijihua

@fanyijihua
Copy link
Collaborator

@moods445 好的呢 🍺

Copy link

@moods445 moods445 left a comment

Choose a reason for hiding this comment

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

@jonjia 已校对完成


You probably figured this one out (good job) — `toUpperCase()` is a type of String method. We’re passing an integer as the argument, thus we can’t call `toUpperCase()` on an integer.
你可能已经发现了这个问题(干的漂亮) — `toUpperCase()` String 的方法,我们将一个整型作为参数传递过去,显然无法调用整型的`toUpperCase()` 方法。
Copy link

@moods445 moods445 Mar 6, 2018

Choose a reason for hiding this comment

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

「显然无法调用整型的toUpperCase() 方法。」 => 「显然不能在整型上调用 toUpperCase() 方法。」


[TypeScript first appeared on 1st of October, 2012\.](https://en.wikipedia.org/wiki/TypeScript) It’s being developed by Microsoft, lead by [Anders Hejlsberg](https://en.wikipedia.org/wiki/Anders_Hejlsberg) (lead architect of [C#](https://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29)) and his team.
[TypeScript 于 2012 年 10 月 1 日正式开源。](https://en.wikipedia.org/wiki/TypeScript) Microsoft 开发维护,[C#](https://en.wikipedia.org/wiki/C_Sharp_%28programming_language%29) 的首席架构师 [Anders Hejlsberg](https://en.wikipedia.org/wiki/Anders_Hejlsberg) 以及他的团队参与了 TypeScript 的开发。
Copy link

Choose a reason for hiding this comment

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

「C# 的首席架构师 Anders Hejlsberg 以及他的团队参与了 TypeScript 的开发。」 => 「Anders Hejlsberg(C# 的首席架构师)和他的团队牵头


![](https://cdn-images-1.medium.com/max/800/1*6LvBeYZZrPTaxNIBkzQKAQ.png)

The tuple expects the first value to be a `number` — but it’s not in this case, it’s a string `"Indrek"` and thus giving us an error.
元组定义了第一个元素是 `number` 类型,但赋值时并不是 `number` 类型,而是一个值为 `"Indrek"` 的 `string` 类型。所以编译结果会报错。
Copy link

Choose a reason for hiding this comment

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

第一个句号换成逗号吧

@goldEli
Copy link
Contributor

goldEli commented Mar 6, 2018

@fanyijihua 校对认领

@fanyijihua
Copy link
Collaborator

@goldEli 妥妥哒 🍻

Copy link
Contributor

@goldEli goldEli left a comment

Choose a reason for hiding this comment

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

@jonjia @leviding 校对完成


#### What’s left are called [_objects_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
#### 剩下的都是 [**objects**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)

* [Functions are first class objects](https://en.wikipedia.org/wiki/Function_object#In_JavaScript)
* [Arrays are special objects](https://stackoverflow.com/a/5048482/5073961)
* [Prototypes are objects](http://raganwald.com/2015/06/10/mixins.html)
Copy link
Contributor

Choose a reason for hiding this comment

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

上面三条,翻译漏了


### The extra types are the following:
### 额外的类型如下:

![](https://cdn-images-1.medium.com/max/800/1*QlcVGtDb2FVJjkQRIh6gLQ.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

图片中的文字是对 tuples 的介绍,我觉得有必要翻译一下,可以用译注的方式写在图片下面


![](https://cdn-images-1.medium.com/max/800/1*QlcVGtDb2FVJjkQRIh6gLQ.png)

Imagine tuples as organized arrays. You predefine the types in the correct order.
元组就是组织好结构的数组,只是按照顺序定义好数组元素的类型
Copy link
Contributor

Choose a reason for hiding this comment

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

元组 =》 元组(tuples)


* * *

![](https://cdn-images-1.medium.com/max/800/1*Bto4sAfIzfV3EIyYS04JmA.png)

In Typescript, you have to define the return type in your functions. Like so:
There are functions which don’t have a `return` statement;
在 TypeScript 中,你需要定义函数返回值的类型。因为有很多没有 `return` 语句的函数。

![](https://cdn-images-1.medium.com/max/800/1*AboEEgZSSq9YvI-Y6KLBgA.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

图片内容,通过译注的方式翻译


![](https://cdn-images-1.medium.com/max/800/1*JJdm0IAG6MOvVwKh-XUS-w.png)

But in case we do return a value, implicitly or explicitly, we can’t have the return type of `Void`
但有时候我们的函数确实有返回值,不管是隐式还是显式地,我们都不能将返回值的类型设置为 `Void`

![](https://cdn-images-1.medium.com/max/800/1*LYPDIzRpqPZtg03qMz_5SQ.png)

* * *

![](https://cdn-images-1.medium.com/max/800/1*DHGUJYw9MdbnobyC1wf0Pg.png)
Copy link
Contributor

Choose a reason for hiding this comment

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

同上


- [**Indrek Lasn (@lasnindrek) | Twitter**: The latest Tweets from Indrek Lasn (@lasnindrek). business propositons: lasnindrek@gmail.com. Zurich, Switzerland twitter.com](https://twitter.com/lasnindrek)

Thanks for reading and taking the time! I appreciate and you’re awesome!
感谢阅读,你很棒!
Copy link
Contributor

Choose a reason for hiding this comment

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

“感谢阅读,你很棒”读起来怪怪的,建议就写“感谢阅读!”。

@jonjia
Copy link
Contributor Author

jonjia commented Mar 8, 2018

@leviding 修改完成, @moods445 @goldEli 感谢校对。
认真考虑了下添加图片翻译的建议,本文主要想轻松的介绍下 TS,不适合引入太多文档的东西。
所以决定不翻译图片内容,请理解。

@leviding leviding merged commit 44c545c into xitu:master Mar 9, 2018
@leviding
Copy link
Member

leviding commented Mar 9, 2018

@jonjia Merge 啦,可以选时间发布呢

@leviding
Copy link
Member

@jonjia 这篇可以发布啦,之后把链接反馈给我哈

@jonjia
Copy link
Contributor Author

jonjia commented Mar 14, 2018

@jonjia jonjia deleted the translation/typescript-javascript-with-super-powers.md branch March 19, 2018 03:31
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.

TypeScript:拥有超能力的 JavaScript
5 participants