zoukankan      html  css  js  c++  java
  • Typescript学习总结之接口

    接口

    用来建立某种代码约定,使得其他开发者在调用某个方法或者创建新的类时必须遵守接口所定义的代码约定

    1. 接口声明属性

    interface IStudent { 
        name: string;
        age: number;
    }
    
    class Student {
    
        constructor(public iStudeng: IStudent) { 
        }
    
    }
    
    var s1 = new Student({name:"zhangsan",age: 30})
    

     

    2. 接口声明方法

    interface IStudent { 
        say();
    }
    
    class Student implements IStudent {
        say() {
            console.log("i am saying");
         }
    }
    
    class HightStudent implements IStudent {
        say() {
            console.log("high school i am saying");
         }
    }
    
    var s1 = new Student()
    

      继承接口的类要实现接口中的方法,如上面的say方法

  • 相关阅读:
    Javascript 进阶
    transform顺序浅谈
    js对象克隆
    js动画最佳实现——requestAnimationFrame
    svg标签
    typeof和instanceof
    js变量浅谈
    X-UA-compatible浅谈
    封装$
    面向对象
  • 原文地址:https://www.cnblogs.com/linlf03/p/8448966.html
Copyright © 2011-2022 走看看