From be691641cbde85059d6c954713b40b7071ef02ee Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Sat, 2 Nov 2024 02:30:50 +0100 Subject: [PATCH] Refactor app.param function - Streamlined the implementation of the app.param function by replacing the for loop with forEach, improving readability. - Maintained JSDoc comments to ensure clarity on the function's purpose and parameters. - Enhanced code maintainability while preserving existing functionality. --- lib/application.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/application.js b/lib/application.js index b19055ec82..0cc711cf92 100644 --- a/lib/application.js +++ b/lib/application.js @@ -314,7 +314,7 @@ app.engine = function engine(ext, fn) { * * See the Router#param() docs for more details. * - * @param {String|Array} name + * @param {(String|Array)} name * @param {Function} fn * @return {app} for chaining * @public @@ -322,15 +322,11 @@ app.engine = function engine(ext, fn) { app.param = function param(name, fn) { if (Array.isArray(name)) { - for (var i = 0; i < name.length; i++) { - this.param(name[i], fn); - } - - return this; + name.forEach((n) => this.param(n, fn)); + } else { + this.router.param(name, fn); } - this.router.param(name, fn); - return this; };