TypeScript笔记八

/**
 * Created by ufo9631 on 2017/5/25.
 */
//一
interface IPerson{
    name:string;
    age:number;
}

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");
    }
}
class  Tiger implements Animal{
    eat()
    {
        console.log("i eat meat");
    }
}

  

原文地址:https://www.cnblogs.com/sumg/p/7841438.html