From a929b5efb5aa7e4aab552819f1a46f31ad1cb0e3 Mon Sep 17 00:00:00 2001 From: toonlink Date: Tue, 20 Aug 2024 18:15:21 -0400 Subject: [PATCH] refactor: one-time cleanups use for instead of foreach --- package.json | 2 +- src/hook.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4b834da..c2126d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spitroast", - "version": "2.0.1", + "version": "2.0.2", "description": "A simple JavaScript function patcher.", "main": "dist/cjs.js", "module": "dist/esm/index.js", diff --git a/src/hook.ts b/src/hook.ts index e402890..5bb46dd 100644 --- a/src/hook.ts +++ b/src/hook.ts @@ -31,8 +31,8 @@ export default function ( // This calls the original function (...args: unknown[]) => isConstruct - ? Reflect.construct(patch.o, args, ctxt) - : patch.o.apply(ctxt, args) + ? Reflect.construct(origFunc, args, ctxt) + : origFunc.apply(ctxt, args) )(...funcArgs); // After patches @@ -40,7 +40,7 @@ export default function ( workingRetVal = hook.call(ctxt, funcArgs, workingRetVal) ?? workingRetVal; // Cleanups (one-times) - patch.c.forEach((c) => c()); + for (const cleanup of patch.c) cleanup() patch.c = []; return workingRetVal;