Skip to content

Commit 8820d5f

Browse files
committed
Translation zh-TW answer 75
1 parent 64a813c commit 8820d5f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

zh-TW/README_zh-TW.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,4 +2344,38 @@ console.log(result);
23442344
</p>
23452345
</details>
23462346

2347+
---
2348+
2349+
###### 75. 將會輸出什麽內容?
2350+
2351+
```javascript
2352+
const box = { x: 10, y: 20 };
2353+
2354+
Object.freeze(box);
2355+
2356+
const shape = box;
2357+
shape.x = 100;
2358+
2359+
console.log(shape);
2360+
```
2361+
2362+
- A: `{ x: 100, y: 20 }`
2363+
- B: `{ x: 10, y: 20 }`
2364+
- C: `{ x: 100 }`
2365+
- D: `ReferenceError`
2366+
2367+
<details><summary><b>答案</b></summary>
2368+
<p>
2369+
2370+
#### 答案: B
2371+
2372+
`Object.freeze` 使我們無法增加、刪除或修改Object的屬性(除非該屬性的值是另一個Object)。
2373+
2374+
當我們建立變數`shape`並等同被凍結的Object`box`時,`shape`也是指一個被凍結的Object。你可以透過使用`Object.isFrozen`檢查一個Object是否被凍結。在這種情況下,`Object.isFrozen(shape)`回傳true,因為變數`shape`也指向一個凍結Object。
2375+
2376+
由於`shape`是被凍結的,而且`x`的值不是一個Object,所以我們不能修改`x`的屬性。 `x`仍然等於`10`,於是`{ x: 10, y: 20 }`被記錄下來。
2377+
2378+
</p>
2379+
</details>
2380+
23472381
---

0 commit comments

Comments
 (0)