File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -2344,4 +2344,38 @@ console.log(result);
2344
2344
</p >
2345
2345
</details >
2346
2346
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
+
2347
2381
---
You can’t perform that action at this time.
0 commit comments