Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. //將 mary 的 name Property attributes 都設為 false
  2. Object.defineProperty(mary,'name',{
  3. value: 'Mary',
  4. writable: false,
  5. enumerable: false,
  6. configurable: false,
  7. })
  8.  
  9. console.log(mary.name)
  10. //印出 Mary
  11.  
  12. //writable 為 false 將無法再次指定值
  13. mary.name = 'Jack'
  14. console.log(mary.name)
  15. //仍然印出 Mary
  16.  
  17. //enumerable 為 false 將無法被 Object.keys 列出
  18. console.log(Object.keys(mary))
  19. //列出空陣列 []
  20.  
  21. //configurable 為 false 將無法刪除
  22. delete mary.name
  23. //回傳 false
  24.  
  25. console.log(mary.name)
  26. //仍然印出 Mary
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement