interface: 接口只声明成员方法,不做实现。
class: 类声明并实现方法。
也就是说:interface只是定义了这个接口会有什么,但是没有告诉你具体是什么。
例如:
interface Point { lng: number; lat: number; sayPosition(): void; }
Point interface 里面包含数值类型的经纬度和一个sayPosition函数,但是具体内容没有定义,需要你自己在子类中实现。
而class则是完整的实现:
class Point { constructor(lng, lat) { this.lng = lng; this.lat = lat; } sayPosition() { console.log("point:", this.lng, this.lat); } }
.