|
@@ -0,0 +1,35 @@
|
|
|
+(function(){
|
|
|
+ /**
|
|
|
+ * 继承
|
|
|
+ * 因为想让多个子类同时继承父类的属性及方法 所以采用继承
|
|
|
+ * 如果子类中的方法与父类中相同 则显示子类中方法 这种情况成为方法重写
|
|
|
+ */
|
|
|
+ class Person2 {
|
|
|
+ name:string;
|
|
|
+ age:number;
|
|
|
+ constructor(name:string,age:number) {
|
|
|
+ this.name = name;
|
|
|
+ this.age = age;
|
|
|
+ }
|
|
|
+ say() {
|
|
|
+ console.log(`我叫${this.name},今年${this.age}岁`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class Child1 extends Person2 {
|
|
|
+ say() {
|
|
|
+ console.log("haha哈")
|
|
|
+ }
|
|
|
+ hello() {
|
|
|
+ console.log("你好a")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let p2 = new Person2('图图',3)
|
|
|
+ console.log(p2)
|
|
|
+ let child1 = new Child1("LiLi",20);
|
|
|
+ console.log(child1);
|
|
|
+ child1.say()
|
|
|
+ child1.hello()
|
|
|
+})()
|
|
|
+// 自动编译 tsc --watch / tsc -w
|