第十二章:接口

版权声明:博客就当自己记的笔记而已~非常感谢博客大神的帮助,若有无意侵权,请联系我,谢谢 https://blog.csdn.net/qq_32963841/article/details/86646012

接口:
用来建立某种代码约定,使得其他开发者在调用某个方法或创建新的类时必须遵循接口所定义的代码约定。
其实在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");
   }
 }

猜你喜欢

转载自blog.csdn.net/qq_32963841/article/details/86646012