1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| <!DOCTYPE html>
```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> </html> <script type="text/javascript"> function Person(name, sex, age, phone, ID){ this.name = name; this.sex = sex; this.age = age; this.phone = phone; this.ID = ID; this.sleep = function(){ console.log("睡觉!") }; this.eat = function(){ console.log("吃饭!"); } } var p1 = new Person("狗子", "男", 19, "1498098344", "410203890839083"); console.log(p1); p1.eat(); p1.sleep(); Person.prototype.shopping = function(){ console.log("陪女朋友逛逛街啦!"); } p1.shopping(); Person.prototype.address = "地球村"; console.log(p1.address); function Student(num, name, sex, age, phone, ID, score){ Person.apply(this, [name, sex, age,phone, ID]);
this.num = num; this.score = score; this.study = function(){ console.log("学生嘛!好好的学习,为了更好的生活!"); } } var F = function(){}; F.prototype = Person.prototype; Student.prototype = new F(); Student.prototype.constructor = Student; var stu = new Student(1, "鹏鹏", "男", 19, "1782987373", "412903893790379", 99); console.log(stu); stu.sleep(); stu.eat(); stu.study(); stu.shopping();
function Teacher(num, name, sex, age, phone, ID, job){ Person.call(this, name, sex, age, phone, ID); this.num = num; this.job = job; this.shangban = function(){ console.log("好好上班!"); } } var F = function(){}; F.prototype = Person.prototype; Teacher.prototype = new F(); Teacher.prototype.constructor = Teacher; var t1 = new Teacher("56", "姣姣啊", "女", 18, "18638520107", "4102937983739873", "前端讲师"); console.log(t1); console.log(t1.name); t1.name = "Aurora"; t1.sleep(); t1.eat(); t1.shangban(); t1.shopping(); var s1 = new Student(); s1.shopping(); </script>
|