0
点赞
收藏
分享

微信扫一扫

第十二章:接口

舍予兄 2022-05-27 阅读 102

接口:
用来建立某种代码约定,使得其他开发者在调用某个方法或创建新的类时必须遵循接口所定义的代码约定。
其实在js里面是么有接口的概念的,但是在TS里面是提供2个关键字的
第一使用方式:用接口声明属性
第二使用方式:用接口声明方法

  interface IPerson{
name: string:
age: nubber;
}

class Person() {
constructor( public config:IPerson) {
var p1 = new Person({
name:"张三",
age:18
});
}
}

   interface Animal {
eat();
}
class Sheep implements Animal {
eat() {
console.log(" I eat grass");
}
}


举报

相关推荐

0 条评论