9.对象的扩展方法.html 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. var obj1 = {
  11. name:"LiLi",
  12. age: 10,
  13. happy:"哈哈哈哈"
  14. }
  15. var obj2 = {
  16. name:"Lucy",
  17. age: 20
  18. }
  19. let arr = [ "11","22"]
  20. console.log([
  21. {
  22. aa:"111"
  23. }
  24. ])
  25. // 1.Object.is() 判断传入的值 是否 全等
  26. // console.log(Object.is("LILI","LILi"));
  27. // 2.Object.assign() 参数二会覆盖参数一的相同属性 不同则合并
  28. // console.log(Object.assign(obj1,obj2))
  29. // 3.Object.setPrototypeOf(对象,对象类型) 设置对象原型类型
  30. let newObj = Object.setPrototypeOf(
  31. obj2,arr
  32. );
  33. console.log(newObj);
  34. // 4.Object.setPrototypeOf 获取对象原型类型
  35. console.log(Object.getPrototypeOf(newObj))
  36. // 5.Object.keys 获取当前对象可枚举的属性名键值
  37. console.log(Object.keys(obj2))
  38. // 6.Object.values 获取当前对象可枚举的属性值键值
  39. console.log(Object.values(obj2))
  40. // 7.Object.entries 获取当前对象可枚举的键值
  41. console.log(Object.entries(obj2))
  42. </script>
  43. </body>
  44. </html>