# Prevent Object.seal

**URL:** <https://es.discourse.group/t/prevent-object-seal/723>\
**Category:** I have questions\
**Created:** [April 3, 2021, 4:01pm UTC](https://es.discourse.group/t/prevent-object-seal/723 "2021-04-03T16:01:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfulton26](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/mfulton26/32/578_2.png) [@mfulton26](https://es.discourse.group/u/mfulton26)\
**Post date:** [April 3, 2021, 4:01pm UTC](https://es.discourse.group/t/prevent-object-seal/723/1 "2021-04-03T16:01:03Z")

</div>

Is there a way of preventing other's code from sealing my objects and/or prototypes?

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 3, 2021, 7:05pm UTC](https://es.discourse.group/t/prevent-object-seal/723/2 "2021-04-03T19:05:23Z")

</div>

Not if you hand out the object. You could provide a Proxy to the object, perhaps?

---

<div class="post-metadata">

**Author:** ![Alan-Liang](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/alan-liang/32/484_2.png) [@Alan-Liang](https://es.discourse.group/u/Alan-Liang)\
**Post date:** [April 4, 2021, 12:16pm UTC](https://es.discourse.group/t/prevent-object-seal/723/3 "2021-04-04T12:16:30Z")

</div>

You can achieve that by monkeypatching `Object.seal`, but I don't think it's a good way.

---

<div class="post-metadata">

**Author:** ![mfulton26](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/mfulton26/32/578_2.png) [@mfulton26](https://es.discourse.group/u/mfulton26)\
**Post date:** [April 4, 2021, 12:20pm UTC](https://es.discourse.group/t/prevent-object-seal/723/4 "2021-04-04T12:20:00Z")

</div>

I agree and if Object.seal were ever made non configurable in the future that would break things.

I find it interesting that I can seal my objects but I can't prevent others from sealing them in a supported way (from what I can tell).

I wonder if we need an Object.open or similar to block calls like preventExtensions, seal, and freeze on objects so that they cannot be tampered with.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [April 4, 2021, 1:54pm UTC](https://es.discourse.group/t/prevent-object-seal/723/5 "2021-04-04T13:54:25Z")

</div>

What is your use case that relies on being able to mutate an object you’ve exposed?

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [April 6, 2021, 1:53am UTC](https://es.discourse.group/t/prevent-object-seal/723/6 "2021-04-06T01:53:49Z")

</div>

Have you considered returning a [proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) whose [`preventExtensions`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/preventExtensions) returns `false`?

```javascript
return new Proxy(object, {
    preventExtensions: () => false,
})

```

If you return this instead of the object directly, `Object.preventExtensions(proxy)`, `Object.seal(proxy)`, and `Object.freeze(proxy)` will all fail, the first because [the boolean result is proxied to the call](https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots-preventextensions), thus [causing the method itself to throw a `TypeError`](https://tc39.es/ecma262/#sec-object.preventextensions) and the second because [they attempt to block further extension before attempting to modify descriptors and skip that step if that itself fails](https://tc39.es/ecma262/#sec-setintegritylevel) and of course [those](https://tc39.es/ecma262/#sec-object.seal) [two](https://tc39.es/ecma262/#sec-object.freeze) methods also throw if those fail early.

---

<div class="post-metadata">

**Author:** ![mfulton26](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/mfulton26/32/578_2.png) [@mfulton26](https://es.discourse.group/u/mfulton26)\
**Post date:** [April 6, 2021, 11:30am UTC](https://es.discourse.group/t/prevent-object-seal/723/7 "2021-04-06T11:30:24Z")

</div>

I was not aware of that as a possibility. Thank you!
