Skip to content

Instantly share code, notes, and snippets.

Array.prototype.clone = function clone<T>(this: Array<T>, deep: boolean, parent: T = null): T[] {
const c = this.map(x => Object.assign(Object.create(x as Object), x));
const classNameMatch = (a, b) => a.constructor && b.constructor && a.constructor.name === b.constructor.name;
if (deep) {
c.forEach(i => {
const keys = Object.keys(i);
keys.forEach(k => {
if (i[k] instanceof Array) {
// an array property, let's see if it's an array of T