TypeScript笔记六
/** * Created by ufo9631 on 2017/5/25. */ class Person{ public name; //不指定访问控制符默认是public //类被实例化的时候会被调用 constructor(name:string){ //console.log("哈哈"); this.name=name; } /* 可以把属性名简写在构造函数里 constructor(public name:string){ //console.log("哈哈"); this.name=name; } */ //访问控制符 public,private ,protected eat() { console.log(name); } } //继承使用关键字extends //用super关键字调用父类方法 class Employee extends Person { code:string; constructor (name:string,code:string) { super(name);//子类的构造函数必须调用父类的构造函数 this.code=code; } work(){ super.eat(); } } //实例化类 var p1=new Person("batman"); //p1.name=""; p1.eat(); var p2=new Person("supermane"); p2.name="supermane"; p2.eat(); var e1=new Employee("继承","123"); e1.eat(); e1.code="123";