From c10b4feeeb7705903593ba134df128c57a823ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20H=C3=AEncu?= Date: Tue, 7 Aug 2018 19:08:49 +0300 Subject: [PATCH] fix(Collection): use `new this.constructor` instead of `new Collection` (#2709) --- src/util/Collection.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/Collection.js b/src/util/Collection.js index 06f54f59c..f8ac733ad 100644 --- a/src/util/Collection.js +++ b/src/util/Collection.js @@ -220,7 +220,7 @@ class Collection extends Map { */ filter(fn, thisArg) { if (typeof thisArg !== 'undefined') fn = fn.bind(thisArg); - const results = new Collection(); + const results = new this.constructor(); for (const [key, val] of this) { if (fn(val, key, this)) results.set(key, val); } @@ -237,7 +237,7 @@ class Collection extends Map { */ partition(fn, thisArg) { if (typeof thisArg !== 'undefined') fn = fn.bind(thisArg); - const results = [new Collection(), new Collection()]; + const results = [new this.constructor(), new this.constructor()]; for (const [key, val] of this) { if (fn(val, key, this)) { results[0].set(key, val); @@ -404,7 +404,7 @@ class Collection extends Map { * @example collection.sort((userA, userB) => userA.createdTimestamp - userB.createdTimestamp); */ sort(compareFunction = (x, y) => +(x > y) || +(x === y) - 1) { - return new Collection([...this.entries()].sort((a, b) => compareFunction(a[1], b[1], a[0], b[0]))); + return new this.constructor([...this.entries()].sort((a, b) => compareFunction(a[1], b[1], a[0], b[0]))); } toJSON() {