面向对象-继承

Posted 喵小娇

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了面向对象-继承相关的知识,希望对你有一定的参考价值。

 1 <script>
 2         function person(name,sex) {
 3             this.name=name;
 4             this.sex=sex;
 5         }
 6 
 7         person.prototype.showName=function () {
 8             alert(我的名字:+this.name);
 9         }
10         person.prototype.showSex=function () {
11             alert(我的sex:+this.sex);
12         }
13         //---------------------------------------------------
14         function worker(name,sex,job) {
15             person.call(this,name,sex);
16             this.job=job;
17         }
18         worker.prototype=person.prototype;
19 
20         worker.prototype.showJob=function () {
21             alert(我的job:+this.job);
22         }
23 
24         var p1=new person(blue,);
25         p1.showName();
26         p1.showSex();
27         
28         var p2=new worker(blue,,程序员);
29         p2.showJob();
30     </script>

 

以上是关于面向对象-继承的主要内容,如果未能解决你的问题,请参考以下文章