Skip to content

Commit 132684b

Browse files
author
howardchi
committed
finished object/ general.md
1 parent cced2bc commit 132684b

File tree

1 file changed

+28
-39
lines changed

1 file changed

+28
-39
lines changed

doc/zh-TW/object/general.md

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
## Object Usage and Properties
1+
## 物件的使用和屬性
22

3-
Everything in JavaScript acts like an object, with the only two exceptions being
4-
[`null`](#core.undefined) and [`undefined`](#core.undefined).
3+
每個變數可以表現像 JavaScript 物件,除了 [`null`](#core.undefined)[`undefined`](#core.undefined)
54

65
false.toString(); // 'false'
76
[1, 2, 3].toString(); // '1,2,3'
@@ -10,37 +9,30 @@ Everything in JavaScript acts like an object, with the only two exceptions being
109
Foo.bar = 1;
1110
Foo.bar; // 1
1211

13-
A common misconception is that number literals cannot be used as
14-
objects. That is because a flaw in JavaScript's parser tries to parse the *dot
15-
notation* on a number as a floating point literal.
12+
一個常見的誤解就是字面值(literal)不是物件。這是因為 JavaScript 編譯器的一個錯誤,它試圖把 *點操作符* 解析為浮點數的字面值的一部分。
1613

17-
2.toString(); // raises SyntaxError
14+
2.toString(); // 出錯: SyntaxError
1815

19-
There are a couple of workarounds that can be used to make number literals act
20-
as objects too.
16+
有很多變通方法可以讓數字的字面值看起來像物件。
2117

22-
2..toString(); // the second point is correctly recognized
23-
2 .toString(); // note the space left to the dot
24-
(2).toString(); // 2 is evaluated first
18+
2..toString(); // 第二個點號可以正常解析
19+
2 .toString(); // 注意點號前面的空格
20+
(2).toString(); // 2 先被計算
2521

26-
### Objects as a Data Type
22+
### 物件做為數據類型
2723

28-
Objects in JavaScript can also be used as [*Hashmaps*][1]; they mainly consist
29-
of named properties mapping to values.
24+
JavaScript 的物件可以作為 [*Hashmaps*][1]使用,主要用來保存命名的建與值的對應關係。
3025

31-
Using an object literal - `{}` notation - it is possible to create a
32-
plain object. This new object [inherits](#object.prototype) from `Object.prototype` and
33-
does not have [own properties](#object.hasownproperty) defined.
26+
使用物件的字面語法 - `{}` - 可以創建一個簡單的物件。 這個新創建的物件從 `Object.prototype` [繼承](#object.prototype),下面,沒有任何 [字定義屬性](#object.hasownproperty)
3427

35-
var foo = {}; // a new empty object
28+
var foo = {}; // 一個空的物件
3629

37-
// a new object with a 'test' property with value 12
30+
// 一個新的物件,有值為 12 的自定義屬性 'test'
3831
var bar = {test: 12};
3932

40-
### Accessing Properties
33+
### 訪問屬性
4134

42-
The properties of an object can be accessed in two ways, via either the dot
43-
notation or the square bracket notation.
35+
有兩種訪問物件的屬性,點操作或是中括號操作。
4436

4537
var foo = {name: 'kitten'}
4638
foo.name; // kitten
@@ -52,15 +44,14 @@ notation or the square bracket notation.
5244
foo.1234; // SyntaxError
5345
foo['1234']; // works
5446

55-
The notations work almost identically, with the only difference being that the
56-
square bracket notation allows for dynamic setting of properties and
57-
the use of property names that would otherwise lead to a syntax error.
47+
兩種語法是相等的,但是中括號在下面兩個情況依然有效
5848

59-
### Deleting Properties
49+
- 動態設定屬性
50+
- 屬性不是一個有較的變數名
6051

61-
The only way to remove a property from an object is to use the `delete`
62-
operator; setting the property to `undefined` or `null` only removes the
63-
*value* associated with the property, but not the *key*.
52+
### 刪除屬性
53+
54+
唯一刪除屬性的方式就是用 `delete` 操作符。設置屬性為 `undefined` 或是 `null` 只有刪除的屬性和值的關聯,沒有真的刪掉屬性
6455

6556
var obj = {
6657
bar: 1,
@@ -77,23 +68,21 @@ operator; setting the property to `undefined` or `null` only removes the
7768
}
7869
}
7970

80-
The above outputs both `bar undefined` and `foo null` - only `baz` was
81-
removed and is therefore missing from the output.
71+
上面的輸出結果有 `bar undefined``foo null`
72+
只有 `baz` 真正被刪除而已,所以從輸出結果中消失。
73+
8274

83-
### Notation of Keys
75+
### 屬姓名的語法
8476

8577
var test = {
8678
'case': 'I am a keyword, so I must be notated as a string',
8779
delete: 'I am a keyword, so me too' // raises SyntaxError
8880
};
8981

90-
Object properties can be both notated as plain characters and as strings. Due to
91-
another mis-design in JavaScript's parser, the above will throw
92-
a `SyntaxError` prior to ECMAScript 5.
82+
物件的屬性名可以使用字符串或是普通的宣告。但是由於 JavaScript 編譯器有個另外一個錯誤設計。
83+
上面的兩種方式在 ECMAScript 5之前都會拋出 `SyntaxError` 的錯誤。
9384

94-
This error arises from the fact that `delete` is a *keyword*; therefore, it must be
95-
notated as a *string literal* to ensure that it will be correctly interpreted by
96-
older JavaScript engines.
85+
這個錯誤的原因是 `delete` 是 JavaScript 語言的一個 *關鍵字* 因此為了在更低的版本能執行最好用 *string literal*
9786

9887
[1]: http://en.wikipedia.org/wiki/Hashmap
9988

0 commit comments

Comments
 (0)