Typescript-基类继承

时间:2019-12-31 04:07:47

标签: typescript oop

我正在尝试了解此旧代码。我了解接口,类是什么,但不了解为什么要从new (this.constructor as any)(this)函数返回clone?你有什么想法吗?

interface IClonable<T> {
  clone(): T
}

export interface IBaseComponent<T> extends IClonable<T> { }

export interface IBaseComponentParams { }

export class BaseComponent<T> implements IBaseComponent<T> {
  constructor(_: IBaseComponentParams) { }

  clone(): T {
    return new (this.constructor as any)(this)
  }
}

0 个答案:

没有答案
相关问题