123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- </head>
- <body>
- </body>
- <script>
- function Person(name, age) {
- this.name = name;
- this.age = age;
- this.run = function () {
- alert(this.name + '在运动');
- }
- }
- Person.prototype.sex = '男';
- Person.prototype.work = function () {
- alert(this.name + '在工作');
- }
- //#region 既继承构造函数属性方法也继承原型链属性方法
- function Web(name, age) {
- Person.call(this, name, age);
- }
- Web.prototype = Person.prototype;
- //#endregion
- Web.prototype.sayHello = function () {
- alert('Hello');
- }
- var w = new Web('张三', 18);
- w.run();
- </script>
- </html>
|