| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>构造函数继承</title>
- </head>
- <body>
- <script>
- function Father() {
- this.name = 'Lucy';
- this.arr = [1, 2, 3];
- this.fn1 = function () {
- console.log("哈哈哈")
- }
- }
- Father.prototype.say = function () {
- console.log("你好")
- }
- function Child() {
- this.age = 10;
- Father.apply(this)
- // Father.call(this)
- }
- const c1 = new Child();
- const c2 = new Child();
- c1.arr.push('00')
- console.log(c1, 'c1');
- console.log(c2, 'c2')
- // c2.say()
- c1.fn1()
- </script>
- </body>
- </html>
|