123456789101112131415161718192021222324252627282930313233343536 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- // 组合继承
- function Father() {
- this.name = '小明';
- this.arr = [1,2,3];
- this.fn1 = function() {
- console.log("这是组合继承");
- }
- }
- Father.prototype.getName = function() {
- return this.name;
- }
- function Child() {
- Father.call(this);
- this.color = 'red';
- }
- Child.prototype = new Father();
- Child.prototype.constructor = Child;
- var news = new Child();
- console.log(news);
-
- </script>
- </body>
- </html>
|