Browse files

modify language.json, index.json,

  • Loading branch information...
chilijung committed Mar 14, 2013
1 parent 4a26176 commit 5804c903bc52bdd878ea635fbf24b06405fcbf3e
Showing with 67 additions and 96 deletions.
  1. +1 −1 doc/language.json
  2. +28 −53 doc/zh-TW/function/
  3. +9 −9 doc/zh-TW/function/
  4. +19 −23 doc/zh-TW/function/
  5. +10 −10 doc/zh-TW/index.json
@@ -1,5 +1,5 @@
"default": "en",
- "listed": ["en", "fi", "ru", "zh", "tr", "pl", "ko", "ja", "es"]
+ "listed": ["en", "fi", "ru", "zh", "tr", "pl", "ko", "ja", "es", "zh-Tw"]
@@ -1,15 +1,12 @@
-## Constructors
+## 建構函式
-Constructors in JavaScript are yet again different from many other languages. Any
-function call that is preceded by the `new` keyword acts as a constructor.
-Inside the constructor - the called function - the value of `this` refers to a
-newly created object. The [prototype](#object.prototype) of this **new**
-object is set to the `prototype` of the function object that was invoked as the
+JavaScript 中的建構函式和其他語言中的建構函式是不同的。
+用 `new` 的關鍵字方式調用的函式都被認為是建構函式。
+在建構函式內部 - 被呼叫的函式 - `this` 指向一個新建立的 `object`。[prototype](#object.prototype) 這是一個新的物件一個被指向函式的 `prototype` 的建構函式。
If the function that was called has no explicit `return` statement, then it
implicitly returns the value of `this` - the new object.
+如果被使用的函式沒有明顯的呼叫 `return` 的表達式,它會回傳一個隱性的 `this` 的新物件。
function Foo() {
this.bla = 1;
@@ -21,16 +18,13 @@ implicitly returns the value of `this` - the new object.
var test = new Foo();
-The above calls `Foo` as constructor and sets the `prototype` of the newly
-created object to `Foo.prototype`.
-In case of an explicit `return` statement, the function returns the value
-specified by that statement, but **only** if the return value is an `Object`.
+在上面的例子中 `Foo` 建立一個建構函式,並設立一個 `prototype` 來創建一個新的物件叫 `Foo.prototype`
+這個情況下它顯示的 `return` 一個表達式,但他 **只** 返回一個 `Object`
function Bar() {
return 2;
- new Bar(); // a new object
+ new Bar(); // 返回一個新物件
function Test() {
this.value = 2;
@@ -39,23 +33,20 @@ specified by that statement, but **only** if the return value is an `Object`.
foo: 1
- new Test(); // the returned object
+ new Test(); // 回傳物件
-When the `new` keyword is omitted, the function will **not** return a new object.
+如果 `new` 的關鍵字被忽略,函式就 **不會** 回傳一個新的物件。
function Foo() {
- this.bla = 1; // gets set on the global object
+ this.bla = 1; // 獲取一個全域的參數
Foo(); // undefined
-While the above example might still appear to work in some cases, due to the
-workings of [`this`](#function.this) in JavaScript, it will use the
-*global object* as the value of `this`.
+雖然上面有些情況也能正常運行,但是由於 JavaScript 中 [`this`](#funciton.this) 的工作原理,這裡的 `this` 指向 *全域對象*
-### Factories
+### 工廠模式
-In order to be able to omit the `new` keyword, the constructor function has to
-explicitly return a value.
+為了不使用 `new` 關鍵字,建構函式必須顯性的返回一個值。
function Bar() {
var value = 1;
@@ -72,25 +63,17 @@ explicitly return a value.
new Bar();
-Both calls to `Bar` return the same thing, a newly create object that
-has a property called `method`, which is a
-It should also be noted that the call `new Bar()` does **not** affect the
-prototype of the returned object. While the prototype will be set on the newly
-created object, `Bar` never returns that new object.
-In the above example, there is no functional difference between using and
-not using the `new` keyword.
+上面兩個呼叫 `Bar` 的方法回傳的值都一樣,一個新創建的擁有 `method` 屬性被返回,這裡創建了一個 [Closure](#function.closures).
+還有注意, `new Bar()`**不會** 改變返回物件的原型。
+因為建構函式的原型會指向剛剛創立的新物件,而在這裡的 `Bar` 沒有把這個新物件返回。
+在上面的例子中,使用或者不使用 `new` 關鍵字沒有什麼功能性的區別
-### Creating New Objects via Factories
-It is often recommended to **not** use `new` because forgetting its use may
-lead to bugs.
+### 通過工廠模式創建的新對象
-In order to create a new object, one should rather use a factory and construct a
-new object inside of that factory.
+常聽到建議 **不要** 使用 `new`,因為如果忘記如何使用它會造成錯誤。
function Foo() {
var obj = {};
@@ -107,22 +90,14 @@ new object inside of that factory.
return obj;
-While the above is robust against a missing `new` keyword and certainly makes
-the use of [private variables](#function.closures) easier, it comes with some
+雖然上面的方式比起 `new` 的調用方式更不容易出錯,並且可以充分的使用 [私有變數](#function.closures)所帶來的便利,但是還是有一些不好的地方
- 1. It uses more memory since the created objects do **not** share the methods
- on a prototype.
- 2. In order to inherit, the factory needs to copy all the methods from another
- object or put that object on the prototype of the new object.
- 3. Dropping the prototype chain just because of a left out `new` keyword
- is contrary to the spirit of the language.
-### In Conclusion
+1. 會占用更多的記憶體,因為創建的物件 **沒有** 辦法放在在同一個原型上。
+2. 為了要用繼承的方式,工廠方法需要複製所有的屬性或是把一個物件作為新的物件的原型。
+3. 放棄原型鏈僅僅是因為防止遺漏 `new` 所帶來的問題,這與語言本身的思想鄉違背。
-While omitting the `new` keyword might lead to bugs, it is certainly **not** a
-reason to drop the use of prototypes altogether. In the end it comes down to
-which solution is better suited for the needs of the application. It is
-especially important to choose a specific style of object creation and use it
+### 結語
+雖然遺漏 `new` 關鍵字可能會導致問題,但這並 **不是** 放棄只用原型的藉口。
@@ -1,12 +1,11 @@
-## Scopes and Namespaces
+## 作用域和命名空間
-Although JavaScript deals fine with the syntax of two matching curly
-braces for blocks, it does **not** support block scope; hence, all that is left
-in the language is *function scope*.
+儘管 JavaScript 支持一個大括號創建的程式碼,但並不支持塊級作用域。
+而僅僅支援 *函式作用域*
- function test() { // a scope
- for(var i = 0; i < 10; i++) { // not a scope
- // count
+ function test() { // 一個作用域
+ for(var i = 0; i < 10; i++) { // 不是一個作用域
+ // 算數
console.log(i); // 10
@@ -16,14 +15,15 @@ in the language is *function scope*.
> **not** as an object literal. This, in conjunction with
> [automatic insertion of semicolons](#core.semicolon), can lead to subtle errors.
There are also no distinct namespaces in JavaScript, which means that everything
gets defined in one *globally shared* namespace.
Each time a variable is referenced, JavaScript will traverse upwards through all
the scopes until it finds it. In the case that it reaches the global scope and
still has not found the requested name, it will raise a `ReferenceError`.
-### The Bane of Global Variables
+### 全域變數的壞處
// script A
foo = '42';
@@ -222,7 +222,7 @@ which, while different in syntax, behave the same way.
// and so on...
-### In Conclusion
+### 結語
It is recommended to always use an *anonymous wrapper* to encapsulate code in
its own namespace. This does not only protect code against name clashes, but it
@@ -1,50 +1,46 @@
-## How `this` Works
+## `this` 的工作原理
-JavaScript has a different concept of what the special name `this` refers to
-than most other programming languages. There are exactly **five** different
-ways in which the value of `this` can be bound in the language.
+JavaScript 有移到完全部屬於其他語言處理 `this` 的處理機制。
+在 **五** 種物同的情況下, `this` 指向的個不相同
-### The Global Scope
+### 全域變數
-When using `this` in global scope, it will simply refer to the *global* object.
+如果再全域範圍內使用 `this`,會指向 *全域* 的物件
-### Calling a Function
+### 呼叫一個函式
-Here, `this` will again refer to the *global* object.
+這裡 `this` 也會指向 *全域* 對象。
-> **ES5 Note:** In strict mode, the global case **no longer** exists.
-> `this` will instead have the value of `undefined` in that case.
+> **ES5 注意:** 在嚴格模式下,不存在全域變數。
+> `this` 將會是 `undefined`
-### Calling a Method
+### 方法調用;
-In this example, `this` will refer to `test`.
+這個例子中, `this` 指向 `test` 物件。
-### Calling a Constructor
+### 呼叫一個建構函式
new foo();
-A function call that is preceded by the `new` keyword acts as
-a [constructor](#function.constructors). Inside the function, `this` will refer
-to a *newly created* `Object`.
+如果函式傾向用 `new` 關鍵詞使用,我們稱這個函式為 [建構函式](#function.constructors)。
+在函式內部, `this` 指向 *新物件的創立*
-### Explicit Setting of `this`
+### 顯示的設置 `this`
function foo(a, b, c) {}
var bar = {};
- foo.apply(bar, [1, 2, 3]); // array will expand to the below
-, 1, 2, 3); // results in a = 1, b = 2, c = 3
+ foo.apply(bar, [1, 2, 3]); // Array 會被擴展,如下所示
+, 1, 2, 3); // 傳遞參數 a = 1, b = 2, c = 3
-When using the `call` or `apply` methods of `Function.prototype`, the value of
-`this` inside the called function gets **explicitly set** to the first argument
-of the corresponding function call.
+當使用 `function.prototype` 上的 `call` 或只 `apply` 方法時,函式內的 `this` 將會被 **顯示設置** 為函式調用的第一個參數。
As a result, in the above example the *method case* does **not** apply, and `this`
inside of `foo` will be set to `bar`.
@@ -53,7 +49,7 @@ inside of `foo` will be set to `bar`.
> literal. So `var obj = {me: this}` will **not** result in `me` referring to
> `obj`, since `this` only gets bound by one of the five listed cases.
-### Common Pitfalls
+### 常見誤解
While most of these cases make sense, the first can be considered another
mis-design of the language because it **never** has any practical use.
@@ -1,15 +1,15 @@
- "title": "JavaScript Garden",
- "langTitle": "JavaScript Garden in English",
- "description": "A Guide to JavaScript's Quirks and Flaws.",
+ "title": "JavaScript 庭院",
+ "langTitle": "JavaScript Garden 繁體中文翻譯",
+ "description": "JavaScript 語言中古怪用法及缺點的文件總集",
"sections": [
- "title": "Intro",
+ "title": "簡介",
"dir": "intro",
"articles": []
- "title": "Objects",
+ "title": "物件",
"dir": "object",
"articles": [
@@ -19,7 +19,7 @@
- "title": "Functions",
+ "title": "函式",
"dir": "function",
"articles": [
@@ -31,15 +31,15 @@
- "title": "Arrays",
+ "title": "陣列",
"dir": "array",
"articles": [
- "title": "Types",
+ "title": "類型",
"dir": "types",
"articles": [
@@ -49,7 +49,7 @@
- "title": "Core",
+ "title": "核心",
"dir": "core",
"articles": [
@@ -59,7 +59,7 @@
- "title": "Other",
+ "title": "其他",
"dir": "other",
"articles": [

0 comments on commit 5804c90

Please sign in to comment.