[js][utility] add applyDecorators()
This commit is contained in:
parent
10cf8b2630
commit
e5a51167f3
10
shared/utility/decorator.mjs
Normal file
10
shared/utility/decorator.mjs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Applies an array of decorators to a given function in a right-to-left order.
|
||||||
|
*
|
||||||
|
* @param {Function[]} decorators - An array of decorator functions to apply.
|
||||||
|
* @param {Function} func - The original function to decorate.
|
||||||
|
* @returns {Function} - The decorated function after applying all the decorators.
|
||||||
|
*/
|
||||||
|
export function applyDecorators(decorators, func) {
|
||||||
|
return decorators.reduceRight((acc, dec) => dec(acc), func);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user