|
@@ -0,0 +1,40 @@
|
|
|
|
|
+<!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>
|
|
|
|
|
+ <!--
|
|
|
|
|
+ 组合继承:
|
|
|
|
|
+ 原型链继承 + 构造函数继承
|
|
|
|
|
+ 实现:call/apply + 原型链
|
|
|
|
|
+ -->
|
|
|
|
|
+ <script>
|
|
|
|
|
+ function Person(x) {
|
|
|
|
|
+ this.x = x;
|
|
|
|
|
+ this.name = '图图';
|
|
|
|
|
+ this.age = 3;
|
|
|
|
|
+ this.list = ['吃饭', '睡觉', '打豆豆'];
|
|
|
|
|
+ }
|
|
|
|
|
+ Person.prototype.say = function () {
|
|
|
|
|
+ console.log("你好");
|
|
|
|
|
+ }
|
|
|
|
|
+ function Child(val) {
|
|
|
|
|
+ Person.call(this,val)
|
|
|
|
|
+ }
|
|
|
|
|
+ Child.prototype = new Person();
|
|
|
|
|
+
|
|
|
|
|
+ let c1 = new Child('北京');
|
|
|
|
|
+ let c2 = new Child('哈尔滨');
|
|
|
|
|
+ c2.list.push("12");
|
|
|
|
|
+ console.log(c1, 'c1', c1.list)
|
|
|
|
|
+ console.log(c2, 'c2', c2.list)
|
|
|
|
|
+ c1.say()
|
|
|
|
|
+ </script>
|
|
|
|
|
+</body>
|
|
|
|
|
+
|
|
|
|
|
+</html>
|