18_原型.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. let arr = [1, 2, 3];
  11. // Array 构造函数 构造函数类似于工厂可以源源不断的生产数组
  12. // arr2 是数组的实例化对象
  13. // 可以通过构造函数实例化很多的数组对象
  14. let arr2 = new Array(1, 2, 3);
  15. console.log(arr);
  16. console.log(arr2);
  17. // constructor 找到自己的构造函数
  18. console.log(arr.constructor);
  19. console.log(arr2.constructor);
  20. // 原型 prototype
  21. // 数组原型
  22. // console.log(Array.prototype);
  23. // // 字符串原型
  24. // console.log(String.prototype);
  25. // // 数字原型
  26. // console.log(Number.prototype);
  27. // // 布尔值原型
  28. // console.log(Boolean.prototype);
  29. // // 函数原型
  30. // console.log(Function.prototype);
  31. // 在数组原型上新增方法
  32. // Array.prototype.loveCoding = function () {
  33. // console.log("我很喜欢编码");
  34. // }
  35. // arr.loveCoding();
  36. // 实例化 的对象 上的原型 __proto__
  37. console.log(arr.__proto__);
  38. </script>
  39. </body>
  40. </html>