Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

Object.isExtensible()

BaselineWidely available

Object.isExtensible() メソッドは、オブジェクトが拡張可能であるか(新しいプロパティを追加することができるかどうか)を判定します。

試してみましょう

const object1 = {};console.log(Object.isExtensible(object1));// Expected output: trueObject.preventExtensions(object1);console.log(Object.isExtensible(object1));// Expected output: false

構文

js
Object.isExtensible(obj)

引数

obj

チェックするオブジェクトです。

返値

論理値で、与えられたオブジェクトが拡張可能であるかどうかを示します。

解説

オブジェクトは既定では拡張可能です。つまり、新しいプロパティの追加が可能であり、[[Prototype]] プロパティに再代入することができます。オブジェクトはObject.preventExtensions(),Object.seal(),Object.freeze(),Reflect.preventExtensions() のいずれかを用いる事で拡張不能に設定する事が可能です。

Object.isExtensible の使用

js
// 新規のオブジェクトは拡張可能const empty = {};Object.isExtensible(empty); // true// その設定は変える事が可能Object.preventExtensions(empty);Object.isExtensible(empty); // false// seal メソッドで封印されたオブジェクトは拡張不可と定義されるconst sealed = Object.seal({});Object.isExtensible(sealed); // false// freeze メソッドで凍結されたオブジェクトも拡張不可と定義されるconst frozen = Object.freeze({});Object.isExtensible(frozen); // false

オブジェクト以外の型強制

ES5 では、このメソッドの引数がオブジェクトではない場合(プリミティブの場合)、TypeError が発生します。 ES2015 以降では、オブジェクトでない引数は、それが拡張不可能な通常のオブジェクトであるかのように扱われ、単にfalse を返します。

js
Object.isExtensible(1);// TypeError: 1 is not an object (ES5 code)Object.isExtensible(1);// false                         (ES2015 code)

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-object.isextensible

ブラウザーの互換性

関連情報

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp