class.html 910 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. </body>
  11. <script>
  12. function Person(name, age) {
  13. this.name = name;
  14. this.age = age;
  15. this.run = function () {
  16. alert(this.name + '在运动');
  17. }
  18. }
  19. Person.prototype.sex = '男';
  20. Person.prototype.work = function () {
  21. alert(this.name + '在工作');
  22. }
  23. //#region 既继承构造函数属性方法也继承原型链属性方法
  24. function Web(name, age) {
  25. Person.call(this, name, age);
  26. }
  27. Web.prototype = Person.prototype;
  28. //#endregion
  29. Web.prototype.sayHello = function () {
  30. alert('Hello');
  31. }
  32. var w = new Web('张三', 18);
  33. w.run();
  34. </script>
  35. </html>