|
@@ -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>
|
|
|
+ /**
|
|
|
+ * 所有构造函数都有个phototype属性 这个属性是该函数的圆形队形
|
|
|
+ * 原型对象的特点:
|
|
|
+ *
|
|
|
+ * 属性 构造函数里
|
|
|
+ * 方法 原型对象下
|
|
|
+ */
|
|
|
+ function Person(name,age) {
|
|
|
+ this.name = name;
|
|
|
+ this.age = age;
|
|
|
+ // console.log(this,this.name,this.age);
|
|
|
+ }
|
|
|
+ Person.prototype.eat = function() {
|
|
|
+ console.log("吃饭");
|
|
|
+ }
|
|
|
+ let aa = new Person("孙悟空",10);
|
|
|
+ // console.log(Person.prototype.constructor)
|
|
|
+ // aa.eat();
|
|
|
+ /**
|
|
|
+ * 子类继承父类
|
|
|
+ * 1.在子类的 构造函数里 调用父类.call()方法
|
|
|
+ * 2.子类的原型对象 = new 父类的继承方法
|
|
|
+ */
|
|
|
+ function Child(name,age) {
|
|
|
+ Person.call(this,name,age);
|
|
|
+ }
|
|
|
+ Child.prototype = new Person();
|
|
|
+ //实例化
|
|
|
+ let bb = new Child("猪八戒",20);
|
|
|
+ console.log(bb.name,bb.age);
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|