继承练习

 1 function extend(subClass,superClass){
 2     var f=function(){};
 3     f.prototype=superClass.prototype;
 4     subClass.prototype=new f();
 5     subClass.prototype.constructor=subClass;
 6 
 7     subClass.superClass=superClass.prototype;
 8     if(superClass.prototype.constructor==Object.prototype.constructor){
 9         superClass.prototype.constructor=superClass;
10     }
11 }
12 
13 
14 function Person(name){
15     this.name=name;
16 }
17 Person.prototype.getNane=function(){
18     return this.name;
19 }
20 
21 function Author(name,books)
22 {
23     Person.call(this,name);
24     Author.superClass.constructor.call(this,name);
25     this.books=books;
26 }
27 extend(Author,Person);
28 
29 Author.prototype.getBooks=function(){
30     return this.books;
31 }
32 
33 
34 
35 Author.prototype.getNane=function(){
36     var name=Author.superClass.getNane.call(this);
37     return name+"111";
38 }
39 
40 var cc=new Author("aa","bb");
41 console.log(cc.getNane());
posted @ 2012-07-04 14:00  kyiku  阅读(185)  评论(0编辑  收藏  举报