Created
July 25, 2016 09:38
-
-
Save korniychuk/c2adcf6f6dfba750e46acb423bde378e to your computer and use it in GitHub Desktop.
TypeScript: extends Array class example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is not work