How could one implement clone() method in TypeScript?

Viewed 40

Suppose there is a class AbstractCollection that may have many sub-classes, which have similar constructors (accepting entries). Is it possible to implement a clone() method in AbstractCollection, that would create and return a new instance of actual sub-class, passing in the entries?

class AbstractCollection<T> {
  constructor(items: T[]) {
    // ...
  }

  clone(): AbstractCollection<T> {
    // TODO: implement
  }
}
1 Answers
Related