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

ES6 translate new #51

Open
wants to merge 1 commit into
base: translate
Choose a base branch
from

Conversation

demongodYY
Copy link

新建了分支 PR 来解决 pull 后文件修改过多的问题。。。把原来的分支关了吧。。

@S1ngS1ng S1ngS1ng mentioned this pull request Aug 1, 2018
4 tasks
Copy link
Contributor

@S1ngS1ng S1ngS1ng left a comment

Choose a reason for hiding this comment

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

  1. <code> 两边不加空格,参考 style-guide
  2. tests 里面的 text 结尾加上句号吧

@@ -292,37 +292,37 @@
"id": "587d7b87367417b2b2512b43",
"title": "Use Arrow Functions to Write Concise Anonymous Functions",
"description": [
"In JavaScript, we often don't need to name our functions, especially when passing a function as an argument to another function. Instead, we create inline functions. We don't need to name these functions because we do not reuse them anywhere else.",
"To achieve this, we often use the following syntax:",
"在JavaScript里,我们会经常遇到不需要给函数命名的情况,尤其是在需要将以个函数作为参数传给另外一个函数的时候,在这些时候,我们会创建行内函数。因为这些函数不会再其他地方复用,所以我们不要给它们命名。",
Copy link
Contributor

Choose a reason for hiding this comment

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

JavaScript 两边加空格

"Arrow functions work really well with higher order functions, such as <code>map()</code>, <code>filter()</code>, and <code>reduce()</code>, that take other functions as arguments for processing collections of data.",
"Read the following code:",
"我们已经见识到了箭头函数在处理数据时候的强大之处。",
"箭头函数在类似 <code>map</code>, <code>filter</code>, <code>reduce</code> 等需要其他函数作为参数来处理数据的高阶函数里会很好用。" ,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里应该使用中文顿号,且不需要加空格

"<blockquote>FBPosts.filter((post) => post.thumbnail !== null && post.shares > 100 && post.likes > 500)</blockquote>",
"This code is more succinct and accomplishes the same task with fewer lines of code.",
"这段代码完成了同样的任务,却变得更加剪短易懂了。",
Copy link
Contributor

Choose a reason for hiding this comment

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

剪短 => 简短

"<hr>",
"Use arrow function syntax to compute the square of only the positive integers (fractions are not integers) in the array <code>realNumberArray</code> and store the new array in the variable <code>squaredIntegers</code>."
"使用箭头函数的语法来计算 <code>squaredIntegers</code> 数组里正整数的平方(分数不是整数)"
Copy link
Contributor

Choose a reason for hiding this comment

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

正整数的平方(分数不是整数) => 正整数(注意,不包含小数)的平方

"Check out this code:",
"<blockquote>function howMany(...args) {<br>&nbsp;&nbsp;return \"You have passed \" + args.length + \" arguments.\";<br>}<br>console.log(howMany(0, 1, 2)); // You have passed 3 arguments<br>console.log(howMany(\"string\", null, [1, 2, 3], { })); // You have passed 4 arguments.</blockquote>",
"The rest operator eliminates the need to check the <code>args</code> array and allows us to apply <code>map()</code>, <code>filter()</code> and <code>reduce()</code> on the parameters array.",
"ES6 推出了用于函数参数的<dfn>rest 操作符</dfn> 帮助我们创建更加灵活的函数。 在 <code>rest</code> 操作符的帮助下,你可以创建有一个变量来接受多个参数的函数。 这些参数被储存在一个可以在函数内部读取的数组中。",
Copy link
Contributor

Choose a reason for hiding this comment

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

逗号应为全角
删掉句号之后多余的空格

"<hr>",
"Use destructuring to obtain the length of the input string <code>str</code>, and assign the length to <code>len</code> in line."
"使用解构语法去得到输入的 <code>str</code> 字符串的长度,并将长度赋值给 <code>len</code>"
Copy link
Contributor

Choose a reason for hiding this comment

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

去得到 => 获取

输入 => 传入

@@ -677,21 +677,21 @@
"id": "587d7b89367417b2b2512b4a",
"title": "Use Destructuring Assignment to Assign Variables from Nested Objects",
"description": [
"We can similarly destructure <em>nested</em> objects into variables.",
"Consider the following code:",
"同样,我们可以将 <em>嵌套的对象</em>解构到变量中。",
Copy link
Contributor

Choose a reason for hiding this comment

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

<em> 空格原则请参考 style-guide

"<blockquote>const a = {<br>&nbsp;&nbsp;start: { x: 5, y: 6},<br>&nbsp;&nbsp;end: { x: 6, y: -9 }<br>};<br>const { start : { x: startX, y: startY }} = a;<br>console.log(startX, startY); // 5, 6</blockquote>",
"In the example above, the variable <code>start</code> is assigned the value of <code>a.start</code>, which is also an object.",
"在上面的例子里,<code>a.start</code> 将值赋给了变量 <code>start</code>,<code>start</code> 同样也是个对象。",
Copy link
Contributor

Choose a reason for hiding this comment

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

使用全角顿号列举

"<hr>",
"Use destructuring assignment to obtain <code>max</code> of <code>forecast.tomorrow</code> and assign it to <code>maxOfTomorrow</code>."
"使用解构赋值来得到 <code>forecast.tomorrow</code> <code>max</code>,并将其赋值给 <code>maxOfTomorrow</code>"
Copy link
Contributor

Choose a reason for hiding this comment

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

得到 => 获取


<code>forecast.tomorrow</code> 的 <code>max</code> 建议 =>
<code>forecast.tomorrow</code>的<code>max</code>属性对应的值

],
"tests": [
{
"text": "<code>maxOfTomorrow</code> equals <code>84.6</code>",
"testString": "assert(getMaxOfTmrw(LOCAL_FORECAST) === 84.6, '<code>maxOfTomorrow</code> equals <code>84.6</code>');"
"text": "<code>maxOfTomorrow</code> 等于 <code>84.6</code>",
Copy link
Contributor

Choose a reason for hiding this comment

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

等于 => 应为

@S1ngS1ng S1ngS1ng added the need update Use when a translation (?) PR has been reviewed and needs to address comments label Aug 1, 2018
"<blockquote>var camper = 'James';<br>var camper = 'David';<br>console.log(camper);<br>// 打印出 'David'</blockquote>",
"在上面的代码中, <code>camper</code> 的初始值为 <code>'James'</code>,然后又被覆盖成了 <code>'David'</code>。",
"在小型的应用中,你可能不会遇到这样的问题,但是当你的代码规模变得更加庞大的时候,就可能会在不经意间覆盖了之前定义的变量。",
"这样的行为不会报错导致了 debug 非常困难。<br>",
Copy link
Contributor

Choose a reason for hiding this comment

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

因为这样的行为不会抛出异常,导致查找和修复 bug 变得很困难。

"However, it is important to understand that objects (including arrays and functions) assigned to a variable using <code>const</code> are still mutable. Using the <code>const</code> declaration only prevents reassignment of the variable identifier.",
"<blockquote>\"use strict\";<br>const s = [5, 6, 7];<br>s = [1, 2, 3]; // throws error, trying to assign a const<br>s[2] = 45; // works just as it would with an array declared with var or let<br>console.log(s); // returns [5, 6, 45]</blockquote>",
"As you can see, you can mutate the object <code>[5, 6, 7]</code> itself and the variable <code>s</code> will still point to the altered array <code>[5, 6, 45]</code>. Like all arrays, the array elements in <code>s</code> are mutable, but because <code>const</code> was used, you cannot use the variable identifier <code>s</code> to point to a different array using the assignment operator.",
"在现代的 JavaScript 里,<code>const</code> 声明有很多用法",
Copy link
Contributor

Choose a reason for hiding this comment

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

在 JavaScript 的最新版本中,用 const 来声明变量有很多好处。

"<blockquote>\"use strict\";<br>const s = [5, 6, 7];<br>s = [1, 2, 3]; // throws error, trying to assign a const<br>s[2] = 45; // works just as it would with an array declared with var or let<br>console.log(s); // returns [5, 6, 45]</blockquote>",
"As you can see, you can mutate the object <code>[5, 6, 7]</code> itself and the variable <code>s</code> will still point to the altered array <code>[5, 6, 45]</code>. Like all arrays, the array elements in <code>s</code> are mutable, but because <code>const</code> was used, you cannot use the variable identifier <code>s</code> to point to a different array using the assignment operator.",
"在现代的 JavaScript 里,<code>const</code> 声明有很多用法",
"一些开发者倾向默认使用 <code>const</code> 来声明所有变量,除非在他们知道需要更改某个变量的值的时候,才会使用 <code>let</code>",
Copy link
Contributor

Choose a reason for hiding this comment

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

开发者优先使用 const 来声明变量,只有当他们确定变量会被重新赋值,他们才会使用 let

"It's time we see how powerful arrow functions are when processing data.",
"Arrow functions work really well with higher order functions, such as <code>map()</code>, <code>filter()</code>, and <code>reduce()</code>, that take other functions as arguments for processing collections of data.",
"Read the following code:",
"我们已经见识到了箭头函数在处理数据时候的强大之处。",
Copy link
Contributor

Choose a reason for hiding this comment

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

曲解原意
这样翻译会不会更友好:是时候展现箭头函数的真正魅力了。

"We can do something similar with objects as well. <dfn>Destructuring assignment</dfn> is special syntax for neatly assigning values taken directly from an object to variables.",
"Consider the following ES5 code:",
"我们之前看到了展开操作符是如何展开数组的内容的。",
"我们队对象也可以做同样的操作。 <dfn>解构赋值</dfn> 就是可以从对象中直接获取对应值的语法。",
Copy link
Contributor

Choose a reason for hiding this comment

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

同样的,解构赋值也可以直接从对象中获取值并赋给变量。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need update Use when a translation (?) PR has been reviewed and needs to address comments
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants