Skip to content

Commit cced2bc

Browse files
author
howardchi
committed
finished intro/ index.md, object/ forinloop.md
1 parent 3cb2af3 commit cced2bc

File tree

2 files changed

+40
-48
lines changed

2 files changed

+40
-48
lines changed

doc/zh-TW/intro/index.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
## Intro
1+
## 簡介
22

3-
**JavaScript Garden** is a growing collection of documentation about the most
4-
quirky parts of the JavaScript programming language. It gives advice to
5-
avoid common mistakes and subtle bugs, as well as performance issues and bad
6-
practices, that non-expert JavaScript programmers may encounter on their
7-
endeavours into the depths of the language.
3+
是一個不斷更新的文件,最主要是要去了解一些 Javascript 比較古怪的部份。
4+
給一些意見來防止遇到一些常見的錯誤和一些難以發現的問題,以及性能問題和不好的習慣。
5+
初學者也可以借此去了解 Javascript 這項語言的特性。
86

9-
JavaScript Garden does **not** aim to teach you JavaScript. Former knowledge
10-
of the language is strongly recommended in order to understand the topics covered
11-
in this guide. In order to learn the basics of the language, please head over to
12-
the excellent [guide][1] on the Mozilla Developer Network.
7+
JavaScript 庭院 並 **不是** 要教導你 Javascript 的語言。
8+
如果要能夠理解這篇文章的內容,你需要事先學習 JavaScript 的基礎知識。
9+
在 Mozilla 開發者網路中有一系列非常棒的學習[guide][1]
1310

14-
## The Authors
1511

16-
This guide is the work of two lovely [Stack Overflow][2] users, [Ivo Wetzel][3]
17-
(Writing) and [Zhang Yi Jiang][4] (Design).
12+
## 作者
1813

19-
## Contributors
14+
這個使用手冊是來自於 [Stack Overflow][2] 的使用者, [Ivo Wetzel][3]
15+
(寫作) 和 [Zhang Yi Jiang][4] (設計).
2016

21-
- [Caio Romão][5] (Spelling corrections)
22-
- [Andreas Blixt][6] (Language corrections)
17+
## 貢獻者
18+
19+
- [Caio Romão][5] (拼寫檢查)
20+
- [Andreas Blixt][6] (語言修正)
21+
22+
## 繁體中文翻譯
23+
24+
- [紀力榮][29]
25+
- [張仲威][30]
2326

2427
## Hosting
2528

2629
JavaScript Garden is hosted on GitHub, but [Cramer Development][7] supports us
2730
with a mirror at [JavaScriptGarden.info][8].
2831

29-
## License
32+
## 許可
3033

31-
JavaScript Garden is published under the [MIT license][9] and hosted on
32-
[GitHub][10]. If you find errors or typos please [file an issue][11] or a pull
33-
request on the repository. You can also find us in the [JavaScript room][12] on
34-
Stack Overflow chat.
34+
JavaScript 庭院是在 [MIT license][9] 許可協議下發佈,並存在於
35+
[GitHub][10]. 如果你有發現錯誤或是打字上的錯誤 [新增一個任務][11] 或者發一個請求。 你也可以在 StackOverflow 的 [JavaScript room][12] 上面找到我們。
3536

3637
[1]: https://developer.mozilla.org/en/JavaScript/Guide
3738
[2]: http://stackoverflow.com/
@@ -45,3 +46,5 @@ Stack Overflow chat.
4546
[10]: https://github.com/BonsaiDen/JavaScript-Garden
4647
[11]: https://github.com/BonsaiDen/JavaScript-Garden/issues
4748
[12]: http://chat.stackoverflow.com/rooms/17/javascript
49+
[29]: http://github.com/chilijung
50+
[30]: http://github.com/wwwy3y3

doc/zh-TW/object/forinloop.md

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,40 @@
1-
## The `for in` Loop
1+
## `for in` 迴圈
22

3-
Just like the `in` operator, the `for in` loop traverses the prototype
4-
chain when iterating over the properties of an object.
3+
就像其他的 `in` 操作符一樣, `for in` 循環也進入所有在物件中的屬性
54

6-
> **Note:** The `for in` loop will **not** iterate over any properties that
7-
> have their `enumerable` attribute set to `false`; for example, the `length`
8-
> property of an array.
5+
> **注意: ** `for in` 迴圈 **不會** 進入那些 `enumerable` 屬性是 `false`,舉例來說, 陣列中 `length` 的屬性
96
10-
// Poisoning Object.prototype
7+
// 修改 Object.prototype
118
Object.prototype.bar = 1;
129

1310
var foo = {moo: 2};
1411
for(var i in foo) {
15-
console.log(i); // prints both bar and moo
12+
console.log(i); // 輸出兩個屬性:bar moo
1613
}
1714

18-
Since it is not possible to change the behavior of the `for in` loop itself, it
19-
is necessary to filter out the unwanted properties inside the loop body;
20-
this is done using the [`hasOwnProperty`](#object.hasownproperty) method of
21-
`Object.prototype`.
15+
由於不可能改變 `for in` 本身的行為,因為有必要過濾出那些不希望在迴圈出現的屬性,這可以用 `Object.prototype` 原型上的 [`hasOwnProperty`](#object.hasownproperty) 的函數來完成。
2216

23-
> **Note:** Since `for in` always traverses the complete prototype chain, it
24-
> will get slower with each additional layer of inheritance added to an object.
17+
> **注意: ** 由於 `for in` 總是要到所有原型鏈裡,因此如果物件的繼承層次太深的話會影響性能。
2518
26-
### Using `hasOwnProperty` for Filtering
2719

28-
// still the foo from above
20+
### `hasOwnProperty` 來過濾
21+
22+
// foo 變數是上面範例中的
2923
for(var i in foo) {
3024
if (foo.hasOwnProperty(i)) {
3125
console.log(i);
3226
}
3327
}
3428

35-
This version is the only correct one to use. Due to the use of `hasOwnProperty`, it
36-
will **only** print out `moo`. When `hasOwnProperty` is left out, the code is
37-
prone to errors in cases where the native prototypes - e.g. `Object.prototype` -
38-
have been extended.
29+
這個版本的程式碼是唯一正確的寫法。由於我們使用了 `hasOwnProperty`,這次 **** 輸出 `moo`
30+
如果不只用這個程式碼在原型物件中(比如 `Object.prototype`)被擴展可能會出錯。
3931

40-
One widely used framework that extends `Object.prototype` is [Prototype][1].
41-
When this framework is included, `for in` loops that do not use
42-
`hasOwnProperty` are guaranteed to break.
32+
一個廣泛的模組 [Prototype][1]就礦展了圓型的 JavaScript 物件。
33+
因此,但這模組包含在頁面中時,不使用 `hasOwnProperty` 過濾的 `for in` 尋難免會出問題。
4334

44-
### In Conclusion
35+
### 總結
4536

46-
It is recommended to **always** use `hasOwnProperty`. Assumptions should never
47-
be made about the environment the code is running in, or whether the native
48-
prototypes have been extended or not.
37+
推薦 **總是** 使用 `hasOwnProperty`。不要對程式碼的環境做任何假設,不要假設原生的對象是否被擴張
4938

5039
[1]: http://www.prototypejs.org/
5140

0 commit comments

Comments
 (0)