Skip to content

Instantly share code, notes, and snippets.

@korniychuk
Created July 25, 2016 09:38
Show Gist options
  • Save korniychuk/c2adcf6f6dfba750e46acb423bde378e to your computer and use it in GitHub Desktop.
Save korniychuk/c2adcf6f6dfba750e46acb423bde378e to your computer and use it in GitHub Desktop.
TypeScript: extends Array class example
'use strict';
class Collection<T> extends Array<T> {
// noinspection JSAnnotator
public constructor(...args: T[]) {
let array = super(...args);
Object.setPrototypeOf(array, this.constructor.prototype);
return array;
}
public print() {
alert(JSON.stringify(this));
}
}
let a = [1, 2, 3];
let b = new Collection<number>(...a);
b.print();
@FrankNewII
Copy link

This is not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment