> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/obj/create/object.create/guard.md).

# guard against accidental modifications

[JS](/web/js.md) ⟩ [value](/web/js/val.md) ⟩ [object](/web/js/val/obj.md) ⟩ [create](/web/js/val/obj/create.md) ⟩ [Object.create()](/web/js/val/obj/create/object.create.md) ⟩ pure object&#x20;

{% hint style="success" %}
[**`Object.create()`**](/web/js/val/obj/create/object.create.md) 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](/web/master/ref/javascript-the-definitive-guide.md) ⟩ 6.2.4 Object.create()&#x20;
  {% endtab %}
  {% endtabs %}
