JavaScript Object.isSealed()

ການອະທິບາຍ ແລະ ການນໍາໃຊ້

Object.isSealed() ວິທີການຕ້ອງການກວດກາວ່າບັນດາວັດຖຸຖືກປິດກັນຫຼືບໍ່。ຖ້າບັນດາວັດຖຸຖືກປິດກັນຫຼັງຈາກນັ້ນ ຈະຫຼັງກັບ true。

ວິທີການອື່ນໆ:

Object.preventExtensions() ອະນຸຍາດແກ້ໄຂ ແຕ່ຫ້າມຕີບອກຂໍ້ມູນຫຼັກ。

Object.seal() Allow modification, but prevent addition and deletion of properties.

Object.freeze() Prevent modification, addition, and deletion of properties.

Object.isExtensible() If the object is extensible, it returns true.

Object.isSealed() If the object is sealed, it returns true.

Object.isFrozen() If the object is frozen, it returns true.

Instance

Example 1

// Create an object
const person = {firstName: "Bill", lastName: "Gates"};
// Seal the object
Object.seal(person);
// This will return true
let answer = Object.isSealed(person);

Try It Yourself

Example 2

// Create an array
const fruits = ["Banana", "Orange", "Apple", "Mango"];
// Seal the array
Object.seal(fruits);
// This will return true
let answer = Object.isSealed(fruits);

Try It Yourself

Syntax

Object.isSealed(object)

Parameter

Parameter Description
object Required. The object to check.

Return Value

Type Description
Boolean If the object is sealed, it returns true, otherwise it returns false.

Browser Support

Object.isSealed() Is a feature of ECMAScript5 (ES5).

Since July 2013, all modern browsers fully support ES5 (JavaScript 2009):

Chrome Edge Firefox Safari Opera
Chrome 23 IE/Edge 11 Firefox 21 Safari 6 Opera 15
September 2012 September 2012 April 2013 July 2012 July 2013