|
@@ -0,0 +1,42 @@
|
|
|
+<!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];
|
|
|
+ }
|
|
|
+ Father.prototype.getName = function () {
|
|
|
+ return this.name;
|
|
|
+ };
|
|
|
+ function Child() {
|
|
|
+ Father.call(this);
|
|
|
+ this.color = "red";
|
|
|
+ }
|
|
|
+ function Way(father,child) {
|
|
|
+ child.prototype = Object.create(father.prototype);
|
|
|
+ child.prototype.constructor = child;
|
|
|
+ }
|
|
|
+ Way(Father,Child);
|
|
|
+
|
|
|
+ Child.prototype.getColor = function() {
|
|
|
+ return this.color;
|
|
|
+ }
|
|
|
+
|
|
|
+ let a1 = new Child();
|
|
|
+ console.log(a1.getName(),'a1.getName');
|
|
|
+ console.log(a1.getColor(),'a1.getColor');
|
|
|
+
|
|
|
+
|
|
|
+ </script>
|
|
|
+ </body>
|
|
|
+</html>
|