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 1)
  • Loading branch information
beginor committed Feb 4, 2017
commit 0a8077d88ab51a2345cfa7483129521ac6b80a8f
9 changes: 6 additions & 3 deletions README-zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -838,13 +838,16 @@ class Cessna extends Airplane {
```
**[⬆ 返回顶部](#代码整洁的-javascript)**

### Avoid type-checking (part 1)
### 避免类型检查 (part 1)
JavaScript is untyped, which means your functions can take any type of argument.
Sometimes you are bitten by this freedom and it becomes tempting to do
type-checking in your functions. There are many ways to avoid having to do this.
The first thing to consider is consistent APIs.

**Bad:**
JavaScript 是无类型的, 这意味着你的函数能接受任何类型的参数。 但是有时又会被这种自由咬伤,
于是又尝试在你的函数中做类型检查。 有很多种方式来避免这个, 第一个要考虑的是一致的 API 。

**不好的:**
```javascript
function travelToTexas(vehicle) {
if (vehicle instanceof Bicycle) {
Expand All @@ -855,7 +858,7 @@ function travelToTexas(vehicle) {
}
```

**Good**:
**好的:**
```javascript
function travelToTexas(vehicle) {
vehicle.move(this.currentLocation, new Location('texas'));
Expand Down