---
description: an object without prototype.
---

# guard against accidental modifications

[JS](../../../..) ⟩ [value](../../..) ⟩ [object](../..) ⟩ [create](..) ⟩ [Object.create()]() ⟩ pure object&#x20;

{% hint style="success" %}
[**`Object.create()`**]() can be used to <mark style="color:yellow;">**protect**</mark> objects from being <mark style="color:yellow;">**modified**</mark> <mark style="color:red;">**accidentally**</mark>.
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}
* replit ⟩ [guard against accidental modifications](https://replit.com/@pegasusroe/guard-against-accidental-modifications#index.js)

```javascript
// the object to protect
const _protected = {
    data: 'DO NOT CHANGE THIS!',
};

// ⭐ guard against accidental modifications
const inherited = Object.create(_protected);

// ⭐ this modifies `inherited` itself, not the `protected` one.
inherited.data = 'Hello, World.';    

inherited.data,     // 'Hello, World.'
_protected.data,    // 'DO NOT CHANGE THIS!'
```
{% endtab %}

{% tab title="📗 參考" %}
* [x] [javascript-the-definitive-guide](../../../../../master/ref/javascript-the-definitive-guide "mention") ⟩ 6.2.4 Object.create()&#x20;
{% endtab %}
{% endtabs %}
