Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
1d0c778
copy to zh-CN , start translation.
beginor Jan 16, 2017
df434cf
try toc
beginor Jan 16, 2017
7461a09
back to top
beginor Jan 16, 2017
c00885c
translate back to top and toc
beginor Jan 16, 2017
e623e0e
translate introduction
beginor Jan 18, 2017
1373345
translate variables
beginor Jan 18, 2017
ae01aaf
trans late part functions
beginor Feb 4, 2017
95435ed
Encapsulate conditionals
beginor Feb 4, 2017
dc08ef3
Avoid negative conditionals
beginor Feb 4, 2017
bbd65e4
Avoid conditionals
beginor Feb 4, 2017
0a8077d
Avoid type-checking (part 1)
beginor Feb 4, 2017
51fb611
Avoid type-checking (part 2)
beginor Feb 4, 2017
736c7e0
Don't over-optimize
beginor Feb 4, 2017
291d6a2
Objects and Data Structures
beginor Feb 4, 2017
7ba2ccf
Use getters and setters
beginor Feb 5, 2017
b7288c4
Remove dead code
beginor Feb 5, 2017
567abaa
Make objects have private members
beginor Feb 5, 2017
69232f8
Classes
beginor Feb 5, 2017
2dd45c8
Single Responsibility Principle
beginor Feb 5, 2017
510212d
Open/Closed Principle
beginor Feb 5, 2017
25966b0
Liskov Substitution Principle
beginor Feb 5, 2017
63893ec
Interface Segregation Principle
beginor Feb 5, 2017
58f44d8
Dependency Inversion Principle
beginor Feb 5, 2017
8b55e2d
Prefer ES2015/ES6 classes over ES5 plain functions
beginor Feb 5, 2017
b4e287c
Use method chaining
beginor Feb 5, 2017
8e442cf
Prefer composition over inheritance
beginor Feb 5, 2017
1460272
testing
beginor Feb 5, 2017
f83e774
Single concept per test
beginor Feb 5, 2017
93398be
concurrency
beginor Feb 5, 2017
4b5192b
Use Promises, not callbacks
beginor Feb 5, 2017
e3bcf8c
Async/Await are even cleaner than Promises
beginor Feb 5, 2017
0d37d16
Error Handling
beginor Feb 10, 2017
0a3931c
Don't ignore caught errors
beginor Feb 10, 2017
6aff7a8
Don't ignore rejected promises
beginor Feb 10, 2017
881061c
miss spell
beginor Feb 10, 2017
0d4a323
formating
beginor Feb 12, 2017
fdae9ad
Use consistent capitalization
beginor Feb 13, 2017
bb99fbb
Function callers and callees should be close
beginor Feb 13, 2017
725d2b2
comments
beginor Feb 13, 2017
ad29269
Only comment things that have business logic complexity
beginor Feb 13, 2017
c697216
Don't leave commented out code in your codebase
beginor Feb 13, 2017
7c8742b
Don't have journal comments
beginor Feb 13, 2017
c5c5795
Avoid positional markers
beginor Feb 13, 2017
f0847c6
Merge remote-tracking branch 'upstream/master'
beginor Feb 13, 2017
f30fd14
update code.
beginor Feb 13, 2017
861e936
add chinese translation link
beginor Feb 13, 2017
844c42d
refact file structor based on origin/master
beginor Feb 13, 2017
b8fe8bc
remove zh-cn temp file.
beginor Feb 15, 2017
08ef8c8
add chinese translation, review in progress.
beginor Feb 15, 2017
00176ef
review part 1
beginor Feb 15, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid type-checking (part 2)
  • Loading branch information
beginor committed Feb 4, 2017
commit 51fb61105e45382faab89f368e12d79c1e1ca066
12 changes: 9 additions & 3 deletions README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ function travelToTexas(vehicle) {
```
**[⬆ 返回顶部](#代码整洁的-javascript)**

### Avoid type-checking (part 2)
### 避免类型检查 (part 2)
If you are working with basic primitive values like strings, integers, and arrays,
and you can't use polymorphism but you still feel the need to type-check,
you should consider using TypeScript. It is an excellent alternative to normal
Expand All @@ -877,7 +877,13 @@ doesn't make up for the lost readability. Keep your JavaScript clean, write
good tests, and have good code reviews. Otherwise, do all of that but with
TypeScript (which, like I said, is a great alternative!).

**Bad:**
如果你使用原始的字符串、 整数和数组, 并且你不能使用多态, 但是你依然感觉到有类型检查的需要,
你应该考虑使用 TypeScript 。 它是一个常规 JavaScript 的优秀的替代品, 因为它在标准的 JavaScript
语法之上为你提供静态类型。 对常规 JavaScript 做人工类型检查的问题是需要大量的冗词来仿造类型安
全而不缺失可读性。 保持你的 JavaScript 简洁, 编写良好的测试, 并有良好的代码审阅, 否则使用
TypeScript (就像我说的, 它是一个伟大的替代品)来完成这些。

**不好的:**
```javascript
function combine(val1, val2) {
if (typeof val1 === 'number' && typeof val2 === 'number' ||
Expand All @@ -889,7 +895,7 @@ function combine(val1, val2) {
}
```

**Good**:
**好的:**
```javascript
function combine(val1, val2) {
return val1 + val2;
Expand Down