es5中的静态属性、静态方法
function Person(){
this.run=function(){
}
}
Person.name='哈哈哈';
Person.run1=function(){
}
ts中定义静态属性和静态方法
class Person{
name:string;
constructor(name:string) {
this.name=name;
}
run(){
console.log(`${
this.name}在跑步`);
}
work(){
console.log(`${
this.name}在工作`);
}
static address:string='丽江';
static print(){
console.log('静态方法');
console.log(`${
Person.address} 静态方法调用实例属性`);
}
}
let p=new Person('张三');
p.run();
p.work();
console.log(Person.address);
Person.print()
多态:父类定义一个方法不去实现,让继承他的子类去实现,每一个子类都有不同的表现形式
多态属于继承
class Animal {
name: string;
constructor(name: string) {
this.name = name;
}
eat() {
}
}
class Dog extends Animal{
constructor