const double = fn => (...a) => fn(...a) * 2;
const addOne = fn => (...a) => fn(...a) + 1;
const square = x => x * x;
const enhanced = addOne(double(square));
enhanced(3); // (9 * 2) + 1 = 19Stack decorators by nesting them β each layer adds behavior on top of the previous.
Multiple decorators can be applied to the same function, each adding different behavior.
Challenge: Create two decorators:
double(fn) - multiplies result by 2addTen(fn) - adds 10 to the resultThen compose them: const f = double(addTen(original))
Example:
const original = (x) => x * 2
const f = double(addTen(original))
f(5) // original(5) = 10, addTen(10) = 20, double(20) = 40