Skip to content

Commit

Permalink
Translation zh-TW answer 75
Browse files Browse the repository at this point in the history
  • Loading branch information
sexyoung committed Jan 27, 2021
1 parent 64a813c commit 8820d5f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions zh-TW/README_zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -2344,4 +2344,38 @@ console.log(result);
</p>
</details>

---

###### 75. 將會輸出什麽內容?

```javascript
const box = { x: 10, y: 20 };

Object.freeze(box);

const shape = box;
shape.x = 100;

console.log(shape);
```

- A: `{ x: 100, y: 20 }`
- B: `{ x: 10, y: 20 }`
- C: `{ x: 100 }`
- D: `ReferenceError`

<details><summary><b>答案</b></summary>
<p>

#### 答案: B

`Object.freeze` 使我們無法增加、刪除或修改Object的屬性(除非該屬性的值是另一個Object)。

當我們建立變數`shape`並等同被凍結的Object`box`時,`shape`也是指一個被凍結的Object。你可以透過使用`Object.isFrozen`檢查一個Object是否被凍結。在這種情況下,`Object.isFrozen(shape)`回傳true,因為變數`shape`也指向一個凍結Object。

由於`shape`是被凍結的,而且`x`的值不是一個Object,所以我們不能修改`x`的屬性。 `x`仍然等於`10`,於是`{ x: 10, y: 20 }`被記錄下來。

</p>
</details>

---

0 comments on commit 8820d5f

Please sign in to comment.