12345678910111213141516171819202122232425262728293031323334 |
- // (function(){})()
- (function() {
- class Money {
- name: string;
- num: number;
- constructor(name:string,num:number) {
- this.name = name;
- this.num = num;
- }
- say() {
- console.log("你好")
- }
- }
- /**
- * super
- * 如果子类要使用父类中属性
- * 子类的构造函数必须对父类的构造函数重新进行接受
- * 使用super
- */
- class A extends Money {
- age:number;
- constructor(name:string,num:number,age:number) {
- super(name,num);
- this.age=age;
- }
- }
- class B extends Money {
- }
- let a = new A('喜羊羊',100,18);
- let b = new B('灰太狼',50);
- console.log(a,'a');
- console.log(b,'b')
- })()
|