当前位置:网站首页>typescript的class结合接口(interface)的简单使用

typescript的class结合接口(interface)的简单使用

2022-06-26 06:13:00 前端一枚

1、接口间继承extends

2、类结合接口使用implements

interface Radio{
    switchRadio(trigger:boolean):void
}
interface Battery{
    checkBatteryStatus():void
}
//接口继承extends
interface RadioWithBattery extends Radio{
    checkBatteryStatus():void
}
//接口接合类implements
class Cellphone implements Radio{
    switchRadio(trigger:boolean){}
}
//接口接合类implements
class Cellphone2 implements RadioWithBattery{
    switchRadio(trigger:boolean){}
    checkBatteryStatus(){}
} 

原网站

版权声明
本文为[前端一枚]所创,转载请带上原文链接,感谢
https://blog.csdn.net/u011200562/article/details/125100595