Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // Object.preventExtensions()メソッド
  2. // オブジェクトの「拡張の禁止」
  3. // 禁止されるのは「プロパティの追加」のみ、プロパティの削除や読み書きには影響なし
  4. //
  5. // Object.isExtensible()メソッド
  6. // オブジェクトの拡張可否を確認する
  7.  
  8. let human = {
  9. name: 'igarashi'
  10. };
  11.  
  12. console.log(Object.isExtensible(human)); // true
  13.  
  14. // オブジェクトの拡張を禁止
  15. Object.preventExtensions(human);
  16.  
  17. console.log(Object.isExtensible(human)); // false
  18.  
  19. // プロパティの追加を試みる
  20. human.sex = 'M'; // Strictモードの場合、ここでエラー
  21.  
  22. console.log('sex' in human); // false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement