1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| abstract class Animal { eat(){ console.log('eat'); } abstract sleep(): void; }
class Dog1 extends Animal{ constructor(name: string) { super(); this.name = name; } name: string run(){} sleep(){ console.log('dog sleep'); } } let dog1 = new Dog1('wangwang'); dog1.eat();
class Cat extends Animal{ sleep(){ console.log('Cat sleep'); } } let cat = new Cat();
let animals: Animal[] = [dog1, cat] animals.forEach(i=>{ i.sleep(); })
class WorkFlow { step1(){ return this; } step2(){ return this; } } new WorkFlow().step1().step2();
class Myflow extends WorkFlow{ next(){ return this; } } new Myflow().next().step1().step2();
|