Blogger Information
Blog 19
fans 0
comment 0
visits 10142
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
用class创建一个类, 并实现自有,共享,静态成员的声明与输出
搬砖来学php
Original
442 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>用class创建一个类, 并实现自有,共享,静态成员的声明与输出</title>
  8. </head>
  9. <body>
  10. <script>
  11. class Class1 {
  12. // 公共成员
  13. sex = "男";
  14. constructor(male, fmale) {
  15. //自有成员
  16. this.male = male;
  17. this.fmale = fmale;
  18. }
  19. //共享成员
  20. getInfo() {
  21. return `${this.male} : ( ${this.fmale} )`;
  22. }
  23. // 静态成员
  24. static status = "enabled";
  25. }
  26. const obj1 = new Class1("男", "女");
  27. console.log(obj1.getInfo());
  28. console.log(obj1.getInfo());
  29. console.log(Class1.status);
  30. // 继承:extends
  31. class Class2 extends Class1 {
  32. constructor(male, fmale, sex) {
  33. super(male, fmale);
  34. this.sex = sex;
  35. }
  36. // 子类中对父类的方法进行扩展
  37. getInfo() {
  38. return `${super.getInfo()} , ${this.sex}`;
  39. }
  40. }
  41. const obj2 = new Class2("中国", "男", "女");
  42. console.log(obj2.getInfo());
  43. // -------------------------------
  44. // 数组与对象解构方法
  45. // 声明
  46. let [name, age] = ["陈老师", "30"];
  47. console.log(name, age);
  48. //更新
  49. [name, age] = ["邱老师", "22"];
  50. console.log(name, age);
  51. // 参数不足给一个默认值
  52. [name, age, sex = "女"] = ["邱老师", "22"];
  53. console.log(name, age, sex);
  54. // 参数过多使用 ....rest
  55. [name, ...rest] = ["严老师", "李老师", "王老师"];
  56. console.log(name);
  57. console.log(rest);
  58. // 使用二数交换
  59. let x = 1;
  60. let y = 2;
  61. [y, x] = [x, y];
  62. console.log([x, y]);
  63. // 对象解构
  64. // 目标是把对象中的属性值保存到对应的,与属性同名的变量中
  65. let { mingzi, nianling, guoji } = {
  66. mingzi: "陈老师",
  67. nianling: 18,
  68. guoji: "中国",
  69. };
  70. console.log(mingzi, nianling, guoji);
  71. // 更新, 用一对大括号,把整个表达式封装起来
  72. ({ mingzi, nianling, guoji } = {
  73. mingzi: "严老师",
  74. nianling: 19,
  75. guoji: "中国人民",
  76. });
  77. console.log(mingzi, nianling, guoji);
  78. // 如果左边模板中的变量存在命名冲突怎么办? 起一个别名id: itemId
  79. let { id: itemId, num, price } = { id: 123, num: 10, price: 1234 };
  80. console.log(itemId, num, price);
  81. </script>
  82. </body>
  83. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post