From 0e1a18c0d31dcd749b415d8fdc7fc79f1b352716 Mon Sep 17 00:00:00 2001 From: Lucas Recknagel Date: Tue, 12 Nov 2019 15:01:10 +0000 Subject: [PATCH] doc: add explanation why keep var with for loop Refs: nceu19-async_hooks This comment will help contributors to understand why keeping var --- lib/internal/async_hooks.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index bf803885cacfa3..78326f10f98e49 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -129,6 +129,7 @@ function emitInitNative(asyncId, type, triggerAsyncId, resource) { active_hooks.call_depth += 1; // Use a single try/catch for all hooks to avoid setting up one per iteration. try { + // Using var here instead of let because "for (var ...)" is faster than let for (var i = 0; i < active_hooks.array.length; i++) { if (typeof active_hooks.array[i][init_symbol] === 'function') { active_hooks.array[i][init_symbol]( @@ -159,6 +160,7 @@ function emitHook(symbol, asyncId) { // Use a single try/catch for all hook to avoid setting up one per // iteration. try { + // Using var here instead of let because "for (var ...)" is faster than let for (var i = 0; i < active_hooks.array.length; i++) { if (typeof active_hooks.array[i][symbol] === 'function') { active_hooks.array[i][symbol](asyncId);