Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Object.preventExtensions()メソッド
- // オブジェクトの「拡張の禁止」
- // 禁止されるのは「プロパティの追加」のみ、プロパティの削除や読み書きには影響なし
- //
- // Object.isExtensible()メソッド
- // オブジェクトの拡張可否を確認する
- let human = {
- name: 'igarashi'
- };
- console.log(Object.isExtensible(human)); // true
- // オブジェクトの拡張を禁止
- Object.preventExtensions(human);
- console.log(Object.isExtensible(human)); // false
- // プロパティの追加を試みる
- human.sex = 'M'; // Strictモードの場合、ここでエラー
- console.log('sex' in human); // false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement