From 7d47091c149bfd63759147cc5f571dfca9639036 Mon Sep 17 00:00:00 2001 From: Ivaylo Stoyanov Date: Wed, 1 Nov 2017 14:14:20 +0200 Subject: [PATCH] Fix forEach callback function getting called in the wrong context --- src/Memorija.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Memorija.ts b/src/Memorija.ts index 2a1aa93..690334b 100644 --- a/src/Memorija.ts +++ b/src/Memorija.ts @@ -177,11 +177,9 @@ export class Memorija implements Map { * @param thisArg */ forEach(callbackfn: (value: V, key: K, map: Map) => void, thisArg?: any): void { - const self = this; - this.map.forEach((v, k) => { - callbackfn(v[1], k, self); - }, thisArg); + callbackfn.apply(thisArg, [v[1], k, this]); + }); } /**