From 5be20b49480cd51a92d970c901b60b09b8f2676a 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 This comment will help contributors to understand why keeping var PR-URL: https://github.com/nodejs/node/pull/30380 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Gireesh Punathil --- lib/internal/async_hooks.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index bf803885cacfa3..6116712fb7cce6 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -129,6 +129,8 @@ 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. + // Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364 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 +161,8 @@ 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. + // Refs: https://github.com/nodejs/node/pull/30380#issuecomment-552948364 for (var i = 0; i < active_hooks.array.length; i++) { if (typeof active_hooks.array[i][symbol] === 'function') { active_hooks.array[i][symbol](asyncId);