Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Reflect.preventExtensions()

この記事は編集レビューを必要としています。ぜひご協力ください

これは Harmony(ECMAScript 6) 提案の一部であり、実験段階の技術です。
この技術の仕様は安定していません。ブラウザ互換性の一覧表を確認してください。またこれらの構文や動作は、仕様変更などにより、新しいバージョンのブラウザでは変更される可能性があるという点に注意してください。

静的な Reflect.preventExtensions() メソッドは、すでにプロパティが追加されたオブジェクトに、新しいプロパティを抑制します (つまり、オブジェクトのさらなる拡張を抑制します)。Object.preventExtensions() に似ていますが、違いがあります

構文

Reflect.preventExtensions(target)

パラメータ

target
拡張を抑止する対象のオブジェクト。

Return value

target に対して成功裡に拡張抑止を設定できたかどうかを示す Boolean

スローされる例外

target が Object ではなかった場合、TypeError がスローされる。

説明

Reflect.preventExtensions メソッドは、すでにプロパティが追加されたオブジェクトに、新しいプロパティを抑制します (つまり、オブジェクトのさらなる拡張を抑制します)。これは Object.preventExtensions() と同様のメソッドです。

Reflect.preventExtensions() を使用する

Object.preventExtensions() も見てください。

// Objects は既定で拡張可能。
var empty = {};
Reflect.isExtensible(empty); // === true

// ...しかし、変更できる。
Reflect.preventExtensions(empty);
Reflect.isExtensible(empty); // === false

Object.preventExtensions() との違い

このメソッドへの最初の引数がオブジェクトではない(プリミティブ)場合、TypeError を引き起こすでしょう。Object.preventExtensions() だと、オブジェクトではない最初の引数はオブジェクトに強制的に変換されます。

Reflect.preventExtensions(1);
// TypeError: 1 はオブジェクトではない。

Object.preventExtensions(1);
// 1

仕様

仕様 状態 コメント
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Reflect.preventExtensions' in that specification.
Standard Initial definition.

ブラウザ実装状況

機能 Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 未サポート 42 (42) 未サポート 未サポート 未サポート
機能 Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 未サポート 未サポート 42.0 (42) 未サポート 未サポート 未サポート

関連項目

ドキュメントのタグと貢献者

 このページの貢献者: YuichiNukiyama
 最終更新者: YuichiNukiyama,