Browse files

finished core/, types/,,

  • Loading branch information...
1 parent 63388c6 commit 7b6fb6905db3492b0910a4616554718e580a5164 @chilijung chilijung committed Mar 14, 2013
Showing with 57 additions and 80 deletions.
  1. +25 −32 doc/zh-TW/core/
  2. +6 −5 doc/zh-TW/types/
  3. +19 −30 doc/zh-TW/types/
  4. +7 −13 doc/zh-TW/types/
@@ -1,23 +1,19 @@
-## The `delete` Operator
+## `delete` 控制符
-In short, it's *impossible* to delete global variables, functions and some other
-stuff in JavaScript which have a `DontDelete` attribute set.
+簡單來說,那是 *不可能* 去刪除一個全域變數,函式和其他東西在 JavaScript 中有一個 `DontDelete` 的屬性
-### Global code and Function code
+### 全域和函式
-When a variable or a function is defined in a global or a [function
-scope](#function.scopes) it is a property of either the Activation object or
-the Global object. Such properties have a set of attributes, one of which is
-`DontDelete`. Variable and function declarations in global and function code
-always create properties with `DontDelete`, and therefore cannot be deleted.
+當一個變數或是一個函式在一個全域範圍被定義或是在一個 [funciton scope](#function.scopes) ,這些屬性可能是動態的物件或是全域的物件。這些特性有一系列的屬性。其中一個就是 `DontDelete`
+在這些變數和函式的宣告都會有一個屬性叫 `DontDelete`,這會使得它無法被刪除。
- // global variable:
- var a = 1; // DontDelete is set
+ // 全域變數
+ var a = 1; // DontDelete 屬性被建立
delete a; // false
a; // 1
// normal function:
- function f() {} // DontDelete is set
+ function f() {} // DontDelete 屬性被建立
delete f; // false
typeof f; // "function"
@@ -26,9 +22,9 @@ always create properties with `DontDelete`, and therefore cannot be deleted.
delete f; // false
f; // 1
-### Explicit properties
+### 明確的屬性
-Explicitly set properties can be deleted normally.
// explicitly set property:
var obj = {x: 1};
@@ -38,28 +34,25 @@ Explicitly set properties can be deleted normally.
obj.x; // undefined
obj.y; // undefined
-In the example above, `obj.x` and `obj.y` can be deleted because they have no
-`DontDelete` atribute. That's why the example below works too.
+在上面的例子中, `obj.x` `obj.y` 可以被刪除是因為他們沒有 `DontDelete` 的屬性。
- // this works fine, except for IE:
+ // 可以運作,除了 IE:
var GLOBAL_OBJECT = this;
a === GLOBAL_OBJECT.a; // true - just a global var
delete GLOBAL_OBJECT.a; // true
GLOBAL_OBJECT.a; // undefined
-Here we use a trick to delete `a`. [`this`](#function.this) here refers
-to the Global object and we explicitly declare variable `a` as its property
-which allows us to delete it.
+這裡我們想要去刪除 `a`。 [`this`](#funciton.this) 這裡指向一個全域的物件,和我們明確了地定義 `a` 是它的屬性,所以可以刪除它。
-IE (at least 6-8) has some bugs, so the code above doesn't work.
+IE 有些臭蟲,所以上面的程式碼無法使用(至少 6~8)
-### Function arguments and built-ins
+### 函式的參數和內建
-Functions' normal arguments, [`arguments` objects](#function.arguments)
-and built-in properties also have `DontDelete` set.
+函式的普通參數,[`arguments` object](#function.arguments) 還有一些內建的屬性都有 `DontDelete` 的建立
- // function arguments and properties:
+ // function 參數和屬性
(function (x) {
delete arguments; // false
@@ -74,12 +67,12 @@ and built-in properties also have `DontDelete` set.
-### Host objects
-The behaviour of `delete` operator can be unpredictable for hosted objects. Due
-to the specification, host objects are allowed to implement any kind of behavior.
+### 接受物件
+控制符可以接受無法預測的物件。由於一些特別的情況,會允許它能夠 `delete`
+### 結語
+`delete` 控制符通常都有難以預料的行為,所以我們只可以安全的刪除顯著的屬性在普通的物件上。
-### In conclusion
-The `delete` operator often has unexpected behaviour and can only be safely
-used to delete explicitly set properties on normal objects.
@@ -1,9 +1,8 @@
-## Type Casting
+## 類型轉換
-JavaScript is a *weakly typed* language, so it will apply *type coercion*
-**wherever** possible.
+JavaScript 是一個 *弱類型* 的程式語言,所以在 **任何** 情況下都可以 *強制類型轉換*
- // These are true
+ // 這些都是真
new Number(10) == 10; // Number.toString() is converted
// back to a number
@@ -13,13 +12,15 @@ JavaScript is a *weakly typed* language, so it will apply *type coercion*
isNaN(null) == false; // null converts to 0
// which of course is not NaN
- // These are false
+ // 下面都假
10 == 010;
10 == '-10';
> **ES5 Note:** Number literals that start with a `0` are interpreted as octal
> (Base 8). Octal support for these has been **removed** in ECMAScript 5 strict
> mode.
To avoid the issues above, use of the [strict equal operator](#types.equality)
is **highly** recommended. Although this avoids a lot of common pitfalls, there
@@ -1,13 +1,12 @@
-## Equality and Comparisons
+## 相等與比較
-JavaScript has two different ways of comparing the values of objects for equality.
+JavaScript 有兩個不同的方式來比較兩個物件是否相等。
-### The Equality Operator
+### 等於操作符
-The equality operator consists of two equal signs: `==`
+等於操作符是由兩個等號組成: `==`
-JavaScript features *weak typing*. This means that the equality operator
-**coerces** types in order to compare them.
+JavaScript 是一個 *弱類型* 語言。這代表它會為了比較兩個值而做 **強制類型轉換**
"" == "0" // false
0 == "" // true
@@ -19,20 +18,14 @@ JavaScript features *weak typing*. This means that the equality operator
null == undefined // true
" \t\r\n" == 0 // true
-The above table shows the results of the type coercion, and it is the main reason
-why the use of `==` is widely regarded as bad practice. It introduces
-hard-to-track-down bugs due to its complicated conversion rules.
+上面的表格可以看出來這些結果強制轉換類型,這也代表說用 `==` 是一個不好的習慣,因為它會很難追蹤問題由於它複雜的規則。
-Additionally, there is also a performance impact when type coercion is in play;
-for example, a string has to be converted to a number before it can be compared
-to another number.
-### The Strict Equality Operator
+### 嚴格等於操作符
-The strict equality operator consists of **three** equal signs: `===`.
-It works like the normal equality operator, except that strict equality
-operator does **not** perform type coercion between its operands.
+不像普通的等於操作符 `===` 不會做強制類型轉換。
"" === "0" // false
0 === "" // false
@@ -44,28 +37,24 @@ operator does **not** perform type coercion between its operands.
null === undefined // false
" \t\r\n" === 0 // false
-The above results are a lot clearer and allow for early breakage of code. This
-hardens code to a certain degree and also gives performance improvements in case
-the operands are of different types.
-### Comparing Objects
+### 比較物件
-While both `==` and `===` are called **equality** operators, they behave
-differently when at least one of their operands is an `Object`.
+雖然 `==``===` 都是等於操作符,但其中有一個操作數為物件時,它的行為就會不同。
{} === {}; // false
new String('foo') === 'foo'; // false
new Number(10) === 10; // false
var foo = {};
foo === foo; // true
-Here, both operators compare for **identity** and **not** equality; that is, they
-will compare for the same **instance** of the object, much like `is` in Python
-and pointer comparison in C.
+在這裡等於操作符比較 **不是** 值的相等,而是否是 **相同** 的身分。
+有點像 Python 的 `is` 和 C 中的指標。
+### 結論
-### In Conclusion
+強烈建議使用 **嚴格等於**
+如果要轉換類型,應該要在 [explicitly](#types.casting)的時候轉換,而不是在語言本身用複雜的轉換規則。
-It is highly recommended to only use the **strict equality** operator. In cases
-where types need to be coerced, it should be done [explicitly](#types.casting)
-and not left to the language's complicated coercion rules.
@@ -1,10 +1,8 @@
-## The `instanceof` Operator
+## `instanceof` 操作符
-The `instanceof` operator compares the constructors of its two operands. It is
-only useful when comparing custom made objects. Used on built-in types, it is
-nearly as useless as the [typeof operator](#types.typeof).
+`instanceof` 操作符用來比較兩個建構函數的操作數。只有在比較字定義的物件時才有意義。這和 [typeof operator](#types.typeof)一樣用處不大。
-### Comparing Custom Objects
+### 比較定意義物件
function Foo() {}
function Bar() {}
@@ -18,21 +16,17 @@ nearly as useless as the [typeof operator](#types.typeof).
Bar.prototype = Foo;
new Bar() instanceof Foo; // false
-### Using `instanceof` with Native Types
+### `instanceof` 比較內置類型
new String('foo') instanceof String; // true
new String('foo') instanceof Object; // true
'foo' instanceof String; // false
'foo' instanceof Object; // false
-One important thing to note here is that `instanceof` does not work on objects
-that originate from different JavaScript contexts (e.g. different documents
-in a web browser), since their constructors will not be the exact same object.
+有一點需要注意的, `instanceof` 不能用來物件來自上下文不同的屬性(例如:瀏覽器中不同的文檔結構),因為它的建構函數不一樣。
### In Conclusion
-The `instanceof` operator should **only** be used when dealing with custom made
-objects that originate from the same JavaScript context. Just like the
-[`typeof`](#types.typeof) operator, every other use of it should be **avoided**.
+`instanceof` 操作符應該 **只** 用來比較同一個 JavaScript 上下文定意義的物件。
+正如 [`typeof`](#types.typeof)操作符一樣,任何其他用法都要避免。

0 comments on commit 7b6fb69

Please sign in to comment.