接口擴(kuò)展 接口可繼承接口
第一種
interface Animal {
eat():void;
}
interface Person extends Animal{
work():void;
}
class Web implements Person{
public name:string;
constructor(name:string){
this.name = name
}
eat(){
console.log(this.name + '吃糧食')
}
work(){
console.log(this.name + '敲代碼')
}
}
var w = new Web('老王');
w.eat()
第二種
interface Animal{
eat():void;
}
interface Penson extends Animal{
work():void;
}
class Programmer {
public name:string;
constructor(name:string){
this.name = name
}
coding(code:string){
console.log(this.name + code)
}
}
class Web extends Programmer implements Person{
constructor(name:string){
super(name)
}
eat(){
console.log(this.name + '吃糧食')
}
work(){
console.log(this.name + '敲代碼')
}
}
var w = new Web('小王')
w.coding('敲代碼')