typescript接口擴展、接口的繼承


 1 //接口擴展:接口可以繼承接口   
 2 
 3 
 4     // interface Animal{
 5 
 6     //     eat():void;
 7     // }
 8 
 9     // interface Person extends Animal{
10 
11     //     work():void;
12     // }
13 
14     // class Web implements Person{
15 
16     //     public name:string;
17     //     constructor(name:string){
18     //         this.name=name;
19     //     }
20 
21     //     eat(){
22 
23     //         console.log(this.name+'喜歡吃饅頭')
24     //     }
25     //     work(){
26 
27     //         console.log(this.name+'寫代碼');
28     //     }
29         
30     // }
31 
32     // var w=new Web('小李');
33 
34     // w.eat();
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46     
47     interface Animal{
48 
49         eat():void;
50     }
51 
52     interface Person extends Animal{
53 
54         work():void;
55     }
56 
57 
58     class Programmer{
59 
60         public name:string;
61         constructor(name:string){
62             this.name=name;
63         }
64         
65         coding(code:string){
66 
67             console.log(this.name+code)
68         }
69     }
70 
71 
72     class Web extends Programmer implements Person{
73         
74         constructor(name:string){
75            super(name)
76         }
77         eat(){
78 
79             console.log(this.name+'喜歡吃饅頭')
80         }
81         work(){
82 
83             console.log(this.name+'寫代碼');
84         }
85         
86     }
87 
88     var w=new Web('小李');
89 
90     // w.eat();
91 
92     w.coding('寫ts代碼');

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM