Object.preventExtensions()

このエントリーをはてなブックマークに追加

Object.preventExtensions()はオブジェクトの拡張を防ぐためのメソッドです。

オブジェクトには拡張可能かどうかを示すExtensible属性が存在しデフォルトではtrueが指定されており拡張可能です。しかしObject.preventExtensions()を適用することでExtensible属性をfalseに変更し拡張を防ぐことができます。

var bar = {foo:"haa"};
console.log(Object.isExtensible(bar));//true
Object.preventExtensions(bar);
console.log(Object.isExtensible(bar));//false

Extensible属性の状態はObject.isExtensible()で調べることができます。

登録日 : 2015年08月17日 最終更新日 : 2015年8月17日

同じカテゴリー(Object)のエントリー

検索

スポンサードリンク

バージョン

リファレンス