Skip to content

Commit 9846c4d

Browse files
authored
Translate 7-Concurrency (hienvd#8)
1 parent 29ef3c0 commit 9846c4d

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Original Repository: [ryanmcdermott/clean-code-javascript](https://github.com/ry
99
4. [Đối tượng và Cấu trúc dữ liệu](#đối-tượng-và-cấu-trúc-dữ-liệu)
1010
5. [Classes](#classes)
1111
6. [Testing](#testing)
12-
7. [Concurrency](#concurrency)
12+
7. [Xử lí đồng thời](#xử-lí-đồng-thời)
1313
8. [Xử lí lỗi](#xử-lí-lỗi)
1414
9. [Định dạng](#định-dạng)
1515
10. [Viết chú thích](#viết-chú-thích)
@@ -1767,12 +1767,12 @@ describe('MakeMomentJSGreatAgain', () => {
17671767
```
17681768
**[⬆ về đầu trang](#mục-lục)**
17691769

1770-
## **Concurrency**
1771-
### Use Promises, not callbacks
1772-
Callbacks aren't clean, and they cause excessive amounts of nesting. With ES2015/ES6,
1773-
Promises are a built-in global type. Use them!
1770+
## **Xử lí đồng thời**
1771+
### Hãy dùng Promise, đừng dùng callback
1772+
Callback thì không được 'sạch sẽ' cho lắm, chúng gây ra quá nhiều đoạn code lồng nhau
1773+
(callback hell). Từ ES2015/ES6, Promise đã được đưa vào Javascript. Hãy sử dụng chúng!
17741774

1775-
**Bad:**
1775+
**Không tốt:**
17761776
```javascript
17771777
require('request').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin', (requestErr, response) => {
17781778
if (requestErr) {
@@ -1790,7 +1790,7 @@ require('request').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin', (req
17901790

17911791
```
17921792

1793-
**Good:**
1793+
**Tốt:**
17941794
```javascript
17951795
require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin')
17961796
.then((response) => {
@@ -1804,16 +1804,16 @@ require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Marti
18041804
});
18051805

18061806
```
1807-
**[back to top](#mục-lục)**
1807+
**[về đầu trang](#mục-lục)**
18081808

1809-
### Async/Await are even cleaner than Promises
1810-
Promises are a very clean alternative to callbacks, but ES2017/ES8 brings async and await
1811-
which offer an even cleaner solution. All you need is a function that is prefixed
1812-
in an `async` keyword, and then you can write your logic imperatively without
1813-
a `then` chain of functions. Use this if you can take advantage of ES2017/ES8 features
1814-
today!
1809+
### Async/Await thì 'sạch sẽ' hơn Promise
1810+
Promise là một sự thay thế 'sạch sẽ' cho callback, nhưng ES2017/ES8 giới thiệu
1811+
async và await, đó thậm chí còn là một giải pháp tốt hơn Promise nữa. Những gì
1812+
bạn cần phải làm là một hàm có tiếp đầu ngữ là từ khoá `async`, và bạn có thể viết
1813+
các lệnh logic mà không cần một chuỗi `then` của các hàm. Hãy sử dụng điều này nếu
1814+
bạn có thể tận dụng các tính năng của ES2017/ES8 ngay hôm nay!
18151815

1816-
**Bad:**
1816+
**Không tốt:**
18171817
```javascript
18181818
require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin')
18191819
.then((response) => {
@@ -1828,7 +1828,7 @@ require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Marti
18281828

18291829
```
18301830

1831-
**Good:**
1831+
**Tốt:**
18321832
```javascript
18331833
async function getCleanCodeArticle() {
18341834
try {
@@ -1840,7 +1840,7 @@ async function getCleanCodeArticle() {
18401840
}
18411841
}
18421842
```
1843-
**[back to top](#mục-lục)**
1843+
**[về đầu trang](#mục-lục)**
18441844

18451845

18461846
## **Xử lí lỗi**
@@ -1971,7 +1971,7 @@ file. Lí tưởng là, hãy giữ cho hàm gọi ở trên hàm được gọi.
19711971
đọc code từ trên xuống, giống như đọc báo vậy. Do đó, hãy làm cho code của chúng
19721972
ta cũng được đọc theo cách đó.
19731973

1974-
**Bad:**
1974+
**Không tốt:**
19751975
```javascript
19761976
class PerformanceReview {
19771977
constructor(employee) {
@@ -2010,7 +2010,7 @@ const review = new PerformanceReview(user);
20102010
review.perfReview();
20112011
```
20122012

2013-
**Good:**
2013+
**Tốt:**
20142014
```javascript
20152015
class PerformanceReview {
20162016
constructor(employee) {
@@ -2049,7 +2049,7 @@ const review = new PerformanceReview(employee);
20492049
review.perfReview();
20502050
```
20512051

2052-
**[⬆ về trang chủ](#mục-lục)**
2052+
**[⬆ về đầu trang](#mục-lục)**
20532053

20542054
## **Viết chú thích**
20552055
### Chỉ nên viết chú thích cho những thứ có logic phức tạp.

0 commit comments

Comments
 (0)