[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/seal [Back]  [Original]

Object.seal() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Object.seal()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

Object.seal() . , . ( : Object.freeze() ).

In this article

const object1 = {
  property1: 42,
};

Object.seal(object1);
object1.property1 = 33;
console.log(object1.property1);
// Expected output: 33

delete object1.property1; // Cannot delete when sealed
console.log(object1.property1);
// Expected output: 33

js
Object.seal(obj);

obj

.

.

(extensible). , . , (non-configurable) . . (data properties) (accessor properties), . Object.freeze() , Object.seal() . , / , strict mode TypeError .

. Object.prototype.__proto__ .

js
var obj = {
  prop: function () {},
  foo: "bar",
};

//   ,      
obj.foo = "baz";
obj.lumpy = "woof";
delete obj.prop;

var o = Object.seal(obj);

assert(o === obj);
assert(Object.isSealed(obj) === true);

//         
obj.foo = "quux";
obj.foo; // 'quux'  

//       
Object.defineProperty(obj, "foo", {
  get: function () {
    return "g";
  },
}); // TypeError 

//       
obj.quaxxor = "the friendly duck"; //      
delete obj.foo; //      

// strict mode       TypeError 
function fail() {
  "use strict";
  delete obj.foo; // TypeError 
  obj.sparky = "arf"; // TypeEror 
}
fail();

// Object.defineProperty()     TypeError 
Object.defineProperty(obj, "ohai", { value: 17 }); // TypeErorr 
Object.defineProperty(obj, "foo", { value: "eit" }); //   

ES5 Object.seal() (, ) TypeError . ES6 TypeError .

js
> Object.seal(1)
TypeError: 1 is not an object // ES5 code

> Object.seal(1)
1                             // ES6 code

Specification
ECMAScript 2027 LanguageSpecification
# sec-object.seal


Web Proxy Viewer  |  New URL  |  Original Page