|
@@ -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>
|
|
|
+ <script>
|
|
|
+ function Person(name, age) {
|
|
|
+ this.name = name;
|
|
|
+ this.age = age;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 构造函数中 写属性
|
|
|
+ * 原型中 写方法
|
|
|
+ */
|
|
|
+ Person.prototype.eat = function () {
|
|
|
+ console.log("今天吃了好多");
|
|
|
+ };
|
|
|
+ var p1 = new Person("Lucy", 18);
|
|
|
+ p1.eat();
|
|
|
+ //constructor 构造器
|
|
|
+ /**
|
|
|
+ * 继承父类的方法(继承方法)
|
|
|
+ * 1.子类构造函数里: 通过调用父类的.call继承
|
|
|
+ * 2.子类的继承对象 = new 父类
|
|
|
+ */
|
|
|
+ console.log(Person.prototype.constructor)
|
|
|
+ function Fn1(name,age) {
|
|
|
+ Person.call(this,name,age);
|
|
|
+ }
|
|
|
+ Fn1.prototype = new Person()
|
|
|
+ Fn1.prototype.constructor = Fn1;
|
|
|
+ var p2 = new Fn1("小明",90);
|
|
|
+ console.log(p2);
|
|
|
+ p2.eat();
|
|
|
+ </script>
|
|
|
+ </body>
|
|
|
+</html>
|